Commit Graph

2164 Commits (ece0e1ea036e6d1c952f304ff74762a12786c37f)
 

Author SHA1 Message Date
Qu Wenruo ece0e1ea03 btrfs-progs: utils: Check nodesize against features
Check nodesize against features, not only sectorsize.
In fact, one of the btrfs-convert and mkfs differs in the nodesize
check.

This patch also provides the basis for later btrfs-convert fix.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-10-02 17:54:04 +02:00
Anand Jain 94789777b9 btrfs-progs: provide fail safe for BTRFS_IOC_GET_FSLABEL ioctl
Old kernels before 3.9 do not provide ioctl BTRFS_IOC_GET_FSLABEL.
So we need to provide a fail safe logic for btrfs-progs running
on those kernel.

In this patch when get_label_mounted() fails on the old kernel
it will fail back to the old method and uses get_label_unmounted(),
where it will read from the disk directly.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-10-02 17:52:10 +02:00
David Sterba 3276a9f519
Btrfs progs v4.2.1
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-20 14:50:06 +02:00
Zhao Lei ebd6d2e683 btrfs-progs: tests: Add '-o loop' to mount command line in convert-tests.sh
To fix following bug:
 # ./convert-tests.sh
     [TEST]   ext2 4k nodesize, btrfs defaults
 failed: mount /root/btrfsprogs/tests/test.img /root/btrfsprogs/tests/mnt
 # tail convert-tests-results.txt
 ...
 ############### mount /root/btrfsprogs/tests/test.img /root/btrfsprogs/tests/mnt
 mount: /root/btrfsprogs/tests/test.img is not a block device (maybe try `-o loop'?)
 failed: mount /root/btrfsprogs/tests/test.img /root/btrfsprogs/tests/mnt

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-20 14:31:02 +02:00
David Sterba 1e6f194075 btrfs-progs: docs: add option variants, defaults and versions to mount options
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-15 00:40:00 +02:00
David Sterba c985a2b104 btrfs-progs: cleanup, update function definitions to be ANSI conformant
Sparse reports:

 warning: non-ANSI function declaration of function

and we're using func(void) elsewhere.

Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-14 23:46:19 +02:00
David Sterba fe2657a707 btrfs-progs: cleanup, mark more functions static
Reported by sparse.

Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-14 23:45:53 +02:00
David Sterba 8ede30c220 btrfs-progs: cleanup, make usage strings static
Reported by sparse.

Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-14 23:45:32 +02:00
Omar Sandoval f18085fd88 btrfs-progs: use calloc instead of malloc+memset for tree roots
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-14 22:04:02 +02:00
Zhao Lei d17313dd4b btrfs-progs: image: close all_devices at the end
Devices opened by check_mounted() in main() should closed before
the exit of btrfs-image.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-11 17:03:39 +02:00
Zhao Lei de554435e8 btrfs-progs: image: don't create unused threads
In case of creating an image without compression, we don't need to
create unused threads.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-11 17:02:52 +02:00
Zhao Lei 50ef0322b4 btrfs-progs: image: fix infinite looping with -t 0
Bug:
 # btrfs-image -t0 -c9 /dev/sda6 /tmp/btrfs_image.img
 (hang)
 # btrfs-image -r -t0 /tmp/btrfs_image.img /dev/sda6
 (hang)

Reason:
 The program need to create at least 1 thread for
 compression/decompression. If the user specifies -t0, it overwrites the
 default value of 1, then the program really creates 0 thread, and
 ends up looping

Fix:
 We can add a check, to make the program not to allow -t0 argument,
 but there is another problem:

For example, on a node with 4 cpus:
 btrfs-image -c9 -t1: 4 threads (1 means use NR_CPUS)
             -c9 -t2: 2 threads
             -c9 -t3: 3 threads
             ...
 (-t1 has more threads than -t2 and -t3)

 So we change to use value of 0 as "use NR_CPUS threads", then:
 btrfs-image [no -t arg]: use NR_CPUS threads
             -t0:         use NR_CPUS threads
             -t val:      use val threads.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-11 17:00:10 +02:00
David Sterba 73a894e51e btrfs-progs: fix cross stripe boundary check
Commit 854437ca3c ("btrfs-progs:
extent-tree: avoid allocating tree block that crosses stripe boundary")
does not work for 64k nodesize. Due to an off-by-one error, all queries
to check_crossing_stripes will return that all extents cross a stripe
and this will lead to a false ENOSPC. This crashes later

$ ./mkfs.btrfs -n 64k image

./mkfs.btrfs(btrfs_reserve_extent+0xb77)[0x417f38]
./mkfs.btrfs(btrfs_alloc_free_block+0x57)[0x417fe0]
./mkfs.btrfs(__btrfs_cow_block+0x163)[0x408eb7]
./mkfs.btrfs(btrfs_cow_block+0xd0)[0x4097c4]
./mkfs.btrfs(btrfs_search_slot+0x16f)[0x40be4d]
./mkfs.btrfs(btrfs_insert_empty_items+0xc0)[0x40d5f9]
./mkfs.btrfs(btrfs_insert_item+0x99)[0x40da5f]
./mkfs.btrfs(btrfs_make_block_group+0x4d)[0x41705c]
./mkfs.btrfs(main+0xeef)[0x434b56]

Holger Hoffstätte reports that this also fixes false positives in case
the nodesize is less than 64k. This happens when the node blocks end at
the stripe boundary.

Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-11 16:46:14 +02:00
Zhao Lei 81a58518d4 btrfs-progs: close inode scan in copy_inodes
We need to call ext2fs_close_inode_scan to release resources from
ext2fs_open_inode_scan.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-09 17:44:21 +02:00
Zhao Lei f248b10786 btrfs-progs: Avoid uninitialized data in output of btrfs-convert
The sequence, transid and reserved fields of inode were writen to disk
with uninitizlized value, this patch fixes it.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-09 17:43:05 +02:00
Zhao Lei 537fb08026 btrfs-progs: fix typo in set/get of btrfs_inode_item::sequence
s/generation/sequence/
for BTRFS_SETGET_STACK_FUNCS(stack_inode_sequence, ...)

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-09 17:42:22 +02:00
David Sterba a365b84a32 btrfs-progs: tests: add crafted and fuzzed images
A collection of several images that were produced in a non-standard way
and cause various errors in check or image tools. They do not fit into
the fsck tests as we're not able to repair any of them, but the tools
should not crash or do out-of-bounds access.

Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-09 17:09:01 +02:00
Arnd Hannemann afff169e1a btrfs-progs: makefile: drop u option from ar invocation
In newer distros (ubuntu 15.10, fedora rawhide) the binutils
ar uses the new D flag per default to build deterministic
binaries.
Without this patch the following warning is issued, when
building btrfs-progs:

    [AR]     libbtrfs.a
/usr/bin/ar: `u' modifier ignored since `D' is the default (see `U')

For libtrfs.a performance benefit of the u option can be neglected,
so drop the u option and silence the warning.

In the future one might want to explicitly add the D option anyway.

Signed-off-by: Arnd Hannemann <arnd@arndnet.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-08 13:53:33 +02:00
David Sterba 59cc65a4e6 btrfs-progs: INSTALL: enhance build instructions
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-07 11:46:32 +02:00
David Sterba 22edaa7e85 btrfs-progs: autogen: add check for pkg-config
Configure uses pkg-config, this should be at least checked at the
autogen time.

Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-07 11:09:17 +02:00
David Sterba a608d60181
Btrfs progs v4.2
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-03 14:29:20 +02:00
David Sterba c3a0a488bd btrfs-progs: btrfstune: remove unnecessary fsid checks
The new fsid members were switched from dynamically allocated to
on-stack in e737a9d56b ("btrfs-progs:
btrfstune: rework change_uuid"), we don't have to do the checks in the
helpers.

Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-02 19:07:51 +02:00
David Sterba a426f18baf btrfs-progs: convert: rework checks of label size
Coverity complains that the fslabel might be longer than the superblock
buffer, down in do_convert.

The label is at most 255 bytes, terminated by zero. Use buffers of the
right size.

Resolves-coverity-id: 1320911
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-02 18:56:54 +02:00
Adam Borowski 13be89d82e btrfs-progs: doc: document btrfs-select-super(8)
Signed-off-by: Adam Borowski <kilobyte@angband.pl>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-02 18:56:54 +02:00
Zhao Lei 11b81f475f btrfs-progs: remove unused argument from block_group_free_all_extent
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-02 18:56:54 +02:00
Zhao Lei 75041ac126 btrfs-progs: Fix some spelling typos in chunk-recover.c
Only comment, not big issue.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-02 18:56:54 +02:00
Zhao Lei 2e53604e6d btrfs-progs: stat info for btrfs rescue chunk-recover
chunk-recover need to use many many time in scan_devices(),
and no output in screen:
 # btrfs rescue chunk-recover /dev/sda6
 (no output here, but need long time)

To notice user that "the command is not hang", this patch add
dynamic updated stat information in above period:
 # btrfs rescue chunk-recover /dev/sda6
 Scanning: DONE in dev[0], 19998441472 in dev[1], DONE in dev[2]
 (until)
 Scanning: DONE in dev0, DONE in dev1, DONE in dev2
 Check chunks successfully with no orphans
 Recover the chunk tree successfully.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-02 18:56:54 +02:00
Zhao Lei 8c6d4e6c7c btrfs-progs: Use long type to get thread's return value
pthread use void * to save return status, we can use this pointer to
save our return value, but we need to keep the same length.

This patch move to use long type variable to save return value
of our thread, to avoid potential invalid memory access.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-02 18:56:54 +02:00
Zhao Lei 1593aa711a btrfs-progs: use for loop for scan_devices
for() is more suitable than while() in this code block.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-02 18:56:54 +02:00
David Sterba 17e1e872d4 btrfs-progs: handle errors in btrfs_wipe_existing_sb
Failure during superblock wiping is not always a hard error as we're
going to overwrite it anyway but it may catch some errors earlier. The
error message is not very descriptive though, because we don't get back
much information from blkid.

Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-02 18:56:52 +02:00
David Sterba c4123e1848 btrfs-progs: use on-stack buffer for superblock
In update_disk_super_on_device,the buffer size is small, allocate it
onstack and get rid of one error path.

Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-02 17:46:30 +02:00
David Sterba 2bac679058 btrfs-progs: image: better error handling in update_disk_super_on_device
Return an error code instead of exitting, more verbose messages.

Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-02 17:45:54 +02:00
Zhao Lei 34fa747ec8 btrfs-progs: tests: Use mount_test_dev for misc-tests/007-subvolume-sync
So this test can support both block device and loop device simply.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-01 14:53:16 +02:00
Zhao Lei d4c4443c2d btrfs-progs: tests: Fix mount fail of 013-extent-tree-rebuild
mount command in old system can not add "-o loop" option automatically
for loop device, and make following test failed:
  # ./fsck-tests.sh
  ...
    [TEST]   013-extent-tree-rebuild
  failed: mount /data/btrfsprogs/tests/test.img /data/btrfsprogs/tests/mnt
  test failed for case 013-extent-tree-rebuild

Considering that $TEST_DEV can be block or loop device, we need determine
our mount option in a condition for both case.

This patch create a wrapper function for above request, to solve current
problem in 013-extent-tree-rebuild, and support similar request in future.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-01 14:53:16 +02:00
Zhao Lei 421e41df49 btrfs-progs: tests: introduce test dev mount helpers
mount command in old system can not add "-o loop" option automatically
for a loop device, and make following test 013-extent-tree-rebuild fail.

Considering that $TEST_DEV can be block or loop device, we need to determine
our mount option in a condition for both case.

Introduce a wrapper that will add the loop options if needed.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-01 14:53:16 +02:00
Zhao Lei 3ca185850b btrfs-progs: tests: Use --no-same-owner option for tar
Some test failed in my nfs dir:
  ...
    [TEST]   006-bad-root-items
  tar: test.img: Cannot change ownership to uid 1000, gid 1000: Invalid argument
  tar: Exiting with failure status due to previous errors
  failed to extract default_case.tar.xz
  test failed for case 006-bad-root-items

It is because the image file's owner is:
 # tar tvf default_case.tar.xz
 -rw-r--r-- fdmanana/fdmanana 2147483648 2014-10-17 17:59 test.img

And make tar failed in chown in nfs.

It is not a big issue because we don't use nfs commonly, but extract
the image file with ownership of current user will be a better choice.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-01 14:52:09 +02:00
David Sterba 123f4bc78c btrfs-progs: makefile: add support for additional build flags
Allow fine tuned build options via EXTRA_CFLAGS and EXTRA_LDFLAGS
variables. Useful for additional debugging flags or warnings etc.

Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-01 14:02:50 +02:00
David Sterba 0cdee628b1 btrfs-progs: use android compat header
Applies to sources where pthreads are used.

Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-01 14:02:49 +02:00
David Sterba 8653831b9f btrfs-progs: add compat header for android
Provide stubs and compat macros for android build.

Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-01 14:02:49 +02:00
kenneth.kang 455ab41f91 btrfs-progs: Add Android build mk file
Add Android.mk to use btrfs on android device.

There are still outstanding problems and build support is incomplete:

1) phread_cancel was changed to pthread_kill due to android didn't
   support that.
2) This module needs lzo library on android/external folder.
3) blkid library doesn't support fully. So have to use -f option to
   work.

Signed-off-by: kenneth.kang <kenneth.kang@lge.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-01 14:02:49 +02:00
Zhao Lei 07cc891d1d btrfs-progs: Simplify all-subvolumn-clean condition for wait_for_subvolume_cleaning
Instead of using a dirty-subvolumn-counter in old code, this patch
turn to use a simple and direct way:
  If (not dirty-subvolumn found in current loop) {
      return all_clean;
  }

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-01 14:02:49 +02:00
Zhao Lei 601c5e1b23 btrfs-progs: Simplify memory allocation for enumerate_dead_subvols
No need prepare memory for enumerate_dead_subvols() in caller, and pass
additional argument for allocated length.

Just do every thing inside enumerate_dead_subvols(), it will not
increase malloc count, but make code simple.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-01 14:02:49 +02:00
Zhao Lei 298746b958 btrfs-progs: Fix wrong return value of wait_for_subvolume_cleaning()
Reproduce:
 # btrfs subvolume sync /mnt/btrfs
 Subvolume id 323 is gone
 # echo $?
 1
 #

Reason:
 wait_for_subvolume_cleaning() return !0 in right case, because
 value of ret is set to "is subvolume clean" state before return.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-01 14:02:49 +02:00
Zhao Lei 6425752ab2 btrfs-progs: Fix infinite loop of btrfs subvolumn sync
We can trigger the bug by following operation:
  (no wait between commands 3~5)
  btrfs subvolume create /mnt/btrfs/mysubvol
  btrfs subvolume snapshot /mnt/btrfs/mysubvol /mnt/btrfs/mysubvol_snap
  btrfs subvolume delete /mnt/btrfs/mysubvol_snap
  btrfs subvolume delete /mnt/btrfs/mysubvol
  btrfs subvolume sync /mnt/btrfs
The last command will not exit.

Reason:
  List of "deleted subvolumes" are not currectly set.

  It caused by a typo of value assign, in detail:
  *ids[idx] = sh->offset;
  should be:
  (*ids)[idx] = sh->offset;
  So only first element is set to right memory address.

  If there are multiple "deleted subvolumes", program will
  keep wait.

Above typo also caused some segment fault in my test.

This patch fixed above bug.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-01 14:02:48 +02:00
Byongho Lee 9a99d2b683 btrfs-progs: fix memory leak in btrfs-convert main()
In btrfs-convert main(), strdup() allocates memory to fslabel but that
memory is not freed. We could fix it by adding free() calls to every
return point, but that would make the code messy because there are
several return paths.
So I fix it by changing the code using strdup() with local array and
strncpy().

And btrfs-convert main() guarantees that string length of fslabel is not
to exceed 'BTRFS_LABEL_SIZE', so it's enough to use strcpy() instead of
strncpy() to copy fslabel in do_convert().

Signed-off-by: Byongho Lee <bhlee.kernel@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-01 14:02:48 +02:00
Zhao Lei 107adbd05d btrfs-progs: tests: umount TEST_MNT in clean-tests.sh
If a testcase failed, we can't run it(or other tests needs mount) again,
  # ./misc-tests.sh 007
   [TEST]   007-subvolume-sync
   failed: fail
   test failed for case 007-subvolume-sync
  # ./misc-tests.sh 007
   [TEST]   007-subvolume-sync
   failed: mount /root/btrfs-progs/tests/test.img /root/btrfs-progs/tests/mnt
   test failed for case 007-subvolume-sync

This patch add "umount $TEST_MNT" to clean-tests.sh, to let user
clean mountpoint easily.

After patch:
  # ./misc-tests.sh  007
   [TEST]   007-subvolume-sync
   failed: fail
   test failed for case 007-subvolume-sync
  #
  # clean-tests.sh
  #
  # ./misc-tests.sh  007
   [TEST]   007-subvolume-sync
   failed: fail
   test failed for case 007-subvolume-sync

Suggested-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
[added sudo helper to umount]
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-01 14:02:48 +02:00
Zhao Lei d4d500d341 btrfs-progs: tests: Introduce init_env to initialize common env variant
For example, $TEST_DIR is common used in severial tests, and have
duplicated code for initialize.

These duplicated code not only benifits harddisk vendor, but have
inconsistent details, as:
  convert-tests.sh: lack of mkdir
  fsck-tests/012-leaf-corruption/test.sh: unnecessary mkdir
  fsck-tests/013-extent-tree-rebuild/test.sh: unnecessary init
  misc-tests/XXX ...
And severial error message:
  _fail "unable to create mount point on $TEST_MNT"
  _fail "failed to create mount point"
  ...

This patch move initizlizaton of $TEST_DIR to common init_env(),
to avoid above problem, and init_env() can be used to add more
things in future.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-01 14:02:48 +02:00
Zhao Lei 665dc49ef6 btrfs-progs: Use common unit parser for btrfs filesystem command
Move to use get_unit_mode_from_arg() for cmds-filesystem.c,
to make "btrfs filesystem df/show/usage"'s unit argument same.

Also have cleanup effect: 19 insertions(+), 181 deletions(-)

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-01 14:02:48 +02:00
Zhao Lei 71d856ba3c btrfs-progs: Use common unit parser for btrfs qgroup command
Move to use get_unit_mode_from_arg() for btrfs qgroup command,
to make "btrfs qgroup show"'s unit argument same with other
tools.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-01 14:01:59 +02:00
Zhao Lei 4483673ba6 btrfs-progs: Use common unit parser for btrfs device command
Move to use get_unit_mode_from_arg() for cmds-device.c,
to make "btrfs device usage"'s unit argument same with other
tools.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-01 14:01:59 +02:00