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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
We are using separate code for parsing unit mode in current code,
better to use common function.
This patch introduces a common function to specify units as arguments
and a common help message, to make every tool in btrfs having same unit
argument.
The benefits are:
1: Unify current tool's arguments for unit
2: Make tools in future easy to implement such argument
3: Changes (enhancement) in common function have effect on all
relative tools
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Current code have following bug for subvolume sync:
1: If there are more than 1 subvolume to sync, the program will
infinitely loop.
2: return !0 in exit
This patch add misc-tests/007-subvolume-sync for above case.
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
In btrfs_add_to_fsid(), strdup() allocates memory to device->name, but
the return value is not checked.
So add the return value check and error handling code.
And clean-up error handling code for ENOMEM case.
Signed-off-by: Byongho Lee <bhlee.kernel@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
In btrfs-map-logical main(), strdup() allocates memory to output_file,
but that memory is not freed.
So add missing free() calls before return.
Signed-off-by: Byongho Lee <bhlee.kernel@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
We can use btrfs_open_dir() to check whether the target dir is
under btrfs mount point before openning, instead of checking it in kernel
through ioctl, and returning a fuzzy error message.
Before patch:
# (/mnt/tmp is not btrfs mountpoint)
#
# btrfs device add -f /dev/sda13 /mnt/tmp
ERROR: error adding the device '/dev/sda13' - Inappropriate ioctl for device
#
After patch:
# btrfs device add -f /dev/sda13 /mnt/tmp
ERROR: not btrfs filesystem: /mnt/tmp
#
Similar fix for device remove and device usage.
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
[renamed to btrfs_open_dir]
Signed-off-by: David Sterba <dsterba@suse.com>
This patch introduce open_btrfs_dir() to open a dir in btrfs
filesystem.
It can be used for several tools in btrfs-progs.
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
[renamed from open_btrfs_dir, adjusted error messages]
Signed-off-by: David Sterba <dsterba@suse.com>