Commit Graph

2702 Commits (72e2a08a5c6d5f12be273e286e3355496e4a2f08)
 

Author SHA1 Message Date
Qu Wenruo fca2f8a8fd btrfs-progs: Introduce function to setup temporary extent tree
Introduce new function, setup_temporary_extent_tree() to build a
temporary extent tree for make_btrfs_v2().

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-07 18:15:19 +02:00
Qu Wenruo 1b8851ec40 btrfs-progs: Introduce function to initialize csum tree
Introduce new function, setup_temp_csum_tree(), to setup temporary
csum tree for make_btrfs_v2().

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-07 18:15:19 +02:00
Qu Wenruo b2da12034a btrfs-progs: Introduce function to initialize fs tree
Introudce new function, setup_temp_fs_tree(), to setup temporary fs tree
for make_btrfs_v2().

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-07 18:15:19 +02:00
Qu Wenruo f0a81c88d0 btrfs-progs: Introduce function to initialize device tree
Introduce new function, setup_temp_device_tree(), to setup temporary
device tree for make_btrfs_v2().

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-07 18:15:19 +02:00
Qu Wenruo 56f26c533e btrfs-progs: Introduce function to setup temporary chunk root
Introduce new function, setup_temp_chunk_root(), to initialize temporary
chunk root for make_btrfs_v2().

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-07 18:15:19 +02:00
Qu Wenruo df20ed3e5e btrfs-progs: Introduce function to setup temporary tree root
Introduce new function, setup_temp_tree_root(), to initialize temporary
tree root for make_btrfs_v2().

The new function will setup tree root at metadata chunk and ensure data
won't be written into metadata chunk.

Also, new make_btrfs_v2() will have a much better code structure than
old make_btrfs().

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-07 18:15:19 +02:00
Qu Wenruo e86e5441a0 btrfs-progs: Introduce function to setup temporary superblock
Introduce a new function, setup_temp_super(), to setup temporary super
for make_btrfs_v2().

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[ use __strncpy_null in setup_temp_super ]
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-07 18:15:19 +02:00
Qu Wenruo 330ca2d6df btrfs-progs: utils: Introduce new function for convert
Introduce new function make_convert_btrfs() for convert.

This new function will have the following features:
1) Allocate temporary sb/metadata/system chunk, avoiding old used data
2) More structured functions
   No more over 1000 lines function, better function split and code
   reuse

This will finally replace current make_btrfs(), but now only used for
convert.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-07 18:15:19 +02:00
Qu Wenruo 522ef705e3 btrfs-progs: convert: Introduce function to calculate the available space
Introduce a new function, calculate_available_space() to get available
space cache_tree data_chunks cache_tree.

Unlike old implementation, this function will do the new work:

1) batch used ext* data space.
   To ensure data chunks will recovery them all.
   And restore the result into mkfs_cfg->convert_data_chunks for later
   use.

2) avoid SB and reserved space at chunk level
   Both batched data space or free space will not cover reserved space,
   like SB or the first 1M.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-07 18:15:19 +02:00
Qu Wenruo 9d615049d2 btrfs-progs: convert: Introduce new function to remove reserved ranges
Introduce functions to remove reserved ranges for later btrfs-convert
rework.

The reserved ranges includes:
1. [0,1M)
2. [btrfs_sb_offset(1), +BTRFS_STRIPE_LEN)
3. [btrfs_sb_offset(2), +BTRFS_STRIPE_LEN)

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-07 18:15:19 +02:00
Qu Wenruo 8031517744 btrfs-progs: convert: Introduce functions to read used space
Before we do real convert, we need to read and build up used space cache
tree for later data/meta separate chunk layout.

This patch will iterate all used blocks in ext2 filesystem and record it
into cctx->used cache tree, for later use.

This provides the very basic of later btrfs-convert rework.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-07 18:15:19 +02:00
Qu Wenruo de34a25eb3 btrfs-progs: convert: add compatibility layer for e2fsprogs < 1.42
The new convert framework copies code from current dumpe2fs, which uses
BIGALLOC feature introduced in e2fsprogs v1.42.

While there are a lot of enterprise distributions which are still using
v1.41 e2fsprogs, this will cause compile error for them.

This patch introduces backward compatibility for new convert framework,
by manually introduce macros for ext2 BIGALLOC feature.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-07 18:15:19 +02:00
David Sterba 75bf151ba3 btrfs-progs: tests: 004-ext2-backup-superblock-ranges, use common helpers for image loop
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-03 17:08:43 +02:00
David Sterba 933de7e034 btrfs-progs: tests: 004-ext2-backup-superblock-ranges, drop unnecessary root privs
We really use root only for mount/umount and access to the ext2_saved
image (that has 0600). Also switch to common variable so we can use
helpers.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-03 17:01:36 +02:00
David Sterba e5f8099464 btrfs-progs: tests: unify test drivers
Remove unnecessary code, add exports to all common variables.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-03 16:53:27 +02:00
David Sterba b5ab8d42b7 btrfs-progs: tests: convert: set common variables
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-03 16:53:27 +02:00
David Sterba b06f44e50b btrfs-progs: tests: clean up the test driver of convert tests
Everything is now in separate tests, and TEST=mask now works.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-03 16:53:27 +02:00
David Sterba bea73f33b9 btrfs-progs: tests: convert: separate ext4 tests
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-03 16:53:27 +02:00
David Sterba cf8cc8ea45 btrfs-progs: tests: convert: separate ext3 tests
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-03 16:53:27 +02:00
David Sterba 79b0946f03 btrfs-progs: tests: convert: separate ext2 tests
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-03 16:53:27 +02:00
David Sterba a8e6d4fdfb btrfs-progs: tests: move convert helpers to a separate file
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-03 16:53:27 +02:00
Qu Wenruo dc4bbc37a1 btrfs-progs: convert-tests: Add test case for backup superblock migration
New convert introduced simpler chunk/extent allocation algorithm, at the
cost of complex backup superblock migration codes.

Use specially built ext2 images to test if btrfs-convert can convert and
rollback images without problem.

All these special ext2 image have blocks/holes across 2nd btrfs backup
superblock.

The naming of test image is like the following:
	|<------superblock migration range----->|
	64M					64M + 64K
|-Data--|-Data--|/Hole//|-Data--|/Hole//|-Data--|--Data--| = drdhdhdrd

These test cases should check all typical layouts and make sure new
convert works.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-03 16:53:25 +02:00
Qu Wenruo fde5ae2e49 btrfs-progs: convert-tests: Add support for custom test scripts
Add support for custom convert test scripts, just like fsck tests.

Instead of generic convert tests, we need more specifically created images
for new convert tests.

This patch provide the needed infrastructure for later convert test
cases.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-03 15:22:18 +02:00
Satoru Takeuchi 97198cd75e btrfs-progs: btrfs-crc: make argc check more strict
Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-03 14:49:43 +02:00
Satoru Takeuchi ff6fe039d3 btrfs-progs: btrfs-crc: improve usage message
- If -c is set, filename argument is ignored.
- Describe about -h option

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-03 14:49:43 +02:00
Satoru Takeuchi 9e4e17f361 btrfs-progs: btrfs-crc: print usage on receiving invalid arguments
Usage is only printed if -h option is set. However it's nice to
do it when wrong option is set or the number of argument is wrong.

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-03 14:49:42 +02:00
Satoru Takeuchi ad1295fb04 btrfs-progs: btrfs-crc should be ignored by git
It's a binary built from btrfs-crc.c

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-03 14:49:42 +02:00
Satoru Takeuchi af4fe0551f btrfs-progs: btrfs-crc: fix build error
Remove the following build error.

   ====================================
   $ make btrfs-crc
       [CC]     btrfs-crc.o
       [LD]     btrfs-crc
   btrfs-crc.o: In function `usage':
   /home/sat/src/btrfs-progs/btrfs-crc.c:26: multiple definition of `usage'
   help.o:/home/sat/src/btrfs-progs/help.c:125: first defined here
   collect2: error: ld returned 1 exit status
   Makefile:294: recipe for target 'btrfs-crc' failed
   make: *** [btrfs-crc] Error 1
   =====================================

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-03 14:49:42 +02:00
David Sterba 835ce31a03 btrfs-progs: use wider int type in btrfs_min_global_blk_rsv_size
We know nodesize should not overflow with the shift, but le'ts make the
code correct if the resulting type can store the full value.

Resolves-coverity-id: 1358120
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-03 14:49:42 +02:00
Qu Wenruo 2171228b20 btrfs-progs: Use new random number API
Replace old and not so informal srand()/rand() calls to new random
number API.

Including btrfs-corrupt-block(main user), btrfs-image and btrfs-crc.

Some tests like dir-test/random-test/quick-test is not modified.
As random-test itself can't even pass build.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-03 14:49:42 +02:00
Qu Wenruo 17239a9c89 btrfs-progs: utils: Introduce new pseudo random API
David has reported some quite chaos usage of pseudo random numbers.
Like using static srand seed, or even calling rand() without setting
seed correctly.

The new pseudo random API will initialize the random seed on its first
calling and use uniformly distributed pseudo random number generator as
backend.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[ renamed variables and functions, added prefixes ]
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 16:43:25 +02:00
Qu Wenruo ee0908ee81 btrfs-progs: corrupt-block: Add support to corrupt extent for skinny metadata
For skinny metadata case, btrfs-corrupt-block can't corrupt a metadata
extent due to the type check missing BTRFS_METADATA_ITEM_KEY.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 15:56:59 +02:00
Qu Wenruo bb3c2ea224 btrfs-progs: convert-tests: Add test for backup superblock migration
New convert framework uses new and simpler chunk layout, while the cost
is the more complex superblock range migration logical, compared to old
convert.

Enhance the convert test script to create file which will takes up 2nd
backup superblock space, to ensure the superblock migration is working
as expected.

Suggested-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 15:37:23 +02:00
David Sterba 205bd5edbe btrfs-progs: tests: document cli-tests in readme
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 14:56:56 +02:00
David Sterba bff6828778 btrfs-progs: tests: convert: dump all superblocks after conversion
We want to see all of them, even if they're not valid.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 14:56:56 +02:00
Lu Fengqi 9088ab6a10 btrfs-progs: make btrfs-image restore to support dup
Previously btrfs-image restore would set the chunk items to have 1 stripe,
even if the chunk is dup. If you use btrfsck on the restored file system,
some dev_extent will not find any relative chunk stripe, and the
bytes-used of dev_item will not equal to the dev_extents's total_bytes.
This patch store a additional physical just for the dup case when build
the in-memory chunk-tree.
Currently btrfsck on the restored file system, only single and dup is no
problem. raid* support should be added in the future.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 14:56:56 +02:00
David Sterba 0993ae5a73 btrfs-progs: tests: run rollback after conversion
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 14:56:56 +02:00
David Sterba 3f063f6bdc btrfs-progs: tests: convert, run md5sum with sudo helper
Some of the files might not end up in the checksum list because of
permissions. This is reported by md5sum as incorrectly formatted lines.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 14:56:56 +02:00
Lu Fengqi 9071a10210 btrfs-progs: tests: add 020-extent-ref-cases
In order to confirm that btrfsck supports to check a variety of
refs, add the
following cases:
* keyed_block_ref
* keyed_data_ref
* shared_block_ref
* shared_data_ref
* no_inline_ref (a extent item without inline ref)
* no_skinny_ref

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 14:56:56 +02:00
Merlin Hartley 57744bd1d2 btrfs-progs: doc: fix typo in btrfs-subvolume
Signed-off-by: Merlin Hartley <merlinhartley@hotmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 14:56:56 +02:00
David Sterba c74214c29b btrfs-progs: switch to common message helpers in utils.c
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 14:56:56 +02:00
David Sterba 5e975516b9 btrfs-progs: fix type mismatch in backtrace dumping functions
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 14:56:56 +02:00
David Sterba c27db1238a btrfs-progs: drop O_CREATE from open_ctree_fs_info
We stat the filesystem path before trying to open it so there's no point
to pass O_CREAT ("btrfs-progs: add stat check in open_ctree_fs_info").

Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 14:56:56 +02:00
Qu Wenruo 6f508a01f5 btrfs-progs: Return earlier for previous item
Follow kernel code to return earlier for btrfs_previous_item() function.

Before this patch, btrfs_previous_item() doesn't use its min_objectid to
exit, this makes caller to check key to exit, and if caller doesn't
check, it will iterate all previous item.

This patch will check min_objectid and type, to early return and save
some time.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 14:56:56 +02:00
Qu Wenruo 7c43be8b57 btrfs-progs: Enhance tree block check by checking empty leaf or node
For btrfs, it's possible to have empty leaf, but empty node is not
possible.

Add check for empty node for tree blocks.

Suggested-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 14:56:56 +02:00
David Sterba 6a0d3bf28d btrfs-progs: makefile: add target for testing installation
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 14:56:56 +02:00
Anand Jain 98410fce1d btrfs-progs: clean up commands.h
This function is declared in utils.h so remove it from commands.h int
test_issubvolume(const char *path);

This function does not exists delete the declaration
get_subvol_name(char *mnt, char *full_path);

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 14:56:56 +02:00
Anand Jain b5ae826637 btrfs-progs: makefile: add clean-all to the usage
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 14:56:56 +02:00
David Sterba 66a2e4eee4 btrfs-progs: device usage: report slack space
The total filesystem space on a given device might be smaller than the
device size. We should report that space as well. The original idea was
to report the 'occupied' size but the term was not all clear, so the
logic was reversed to report the slack space.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 14:56:56 +02:00
David Sterba 16570509f6 btrfs-progs: docs: compression is disabled with nodatasum/nodatacow
Explicitly mention the constraints in all involved options.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 14:56:56 +02:00