Commit Graph

158 Commits (2e1932e6a380a0cf94501e31f0c0f7814f73378e)

Author SHA1 Message Date
Qu Wenruo 1733989352 btrfs-progs: mkfs: Use the whole file or block device to mkfs for rootdir
For --rootdir, even for large existing file or block device, it will
always shrink the resulting filesystem.

The problem is, mkfs.btrfs will try to calculate the dir size, and use
it as @block_count to mkfs, which makes the filesystem shrunk.

Fix it by trying to get the original block device or file size as
@block_count, so mkfs.btrfs can use the full file/block device for
--rootdir option.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-08 18:15:20 +01:00
Qu Wenruo 0855a8cd43 btrfs-progs: mkfs: fix regression preventing --rootdir to create file
Commit 460e93f25754 ("btrfs-progs: mkfs: check the status of file at mkfs")
will try to check the file state before creating fs on it.

The check is mostly fine for normal mkfs case, while for --rootdir
option, it's allowed to create a new file if the destination file
doesn't exist.

Fix it by allowing non-existent file if --rootdir is specified.

Fixes: 460e93f25754 ("btrfs-progs: mkfs: check the status of file at mkfs")
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-08 18:15:16 +01:00
Jeff Mahoney a5ce5d2198 btrfs-progs: extent-cache: actually cache extent buffers
We have the infrastructure to cache extent buffers but we don't actually
do the caching.  As soon as the last reference is dropped, the buffer
is dropped.  This patch keeps the extent buffers around until the max
cache size is reached (defaults to 25% of memory) and then it drops
the last 10% of the LRU to free up cache space for reallocation.  The
cache size is configurable (for use by e.g. lowmem) when the cache is
initialized.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
[ update codingstyle, switch total_memory to bytes ]
Signed-off-by: David Sterba <dsterba@suse.com>
2017-10-06 13:41:06 +02:00
Misono, Tomohiro 26908f6146 btrfs-progs: change seen_fsid to hold fd and DIR
Change seen_fsid to hold fd and DIR in order to keep access to each fs.
This will be used for 'subvol delete --commit-after'.

Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>
Reviewed-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-10-06 13:23:30 +02:00
Misono, Tomohiro 836aa5202a btrfs-progs: move seen_fsid to utils.c
Move is_seen_fsid()/add_seen_fsid()/free_seen_fsid() to common functions.
This will be used for 'subvol delete --commit-after'.

Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>
Reviewed-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-10-06 13:23:28 +02:00
Misono, Tomohiro 448763c64a btrfs-progs: move get_fsid() to utils.c
Make get_fsid() to a common functions.
This will be used for 'subvol delete --commit-after'.

Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>
Reviewed-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-10-06 13:23:27 +02:00
Misono, Tomohiro 88ef0b8397 btrfs-progs: inspect rootid: Allow a file to be specified
Since cmd_inspect_rootid() calls btrfs_open_dir(), it rejects a file to
be specified. But as the document says, a file should be supported.

This patch introduces btrfs_open_file_or_dir(), which is a counterpart
of btrfs_open_dir(), to safely check and open btrfs file or directory.
The original btrfs_open_dir() content is moved to btrfs_open() and shared
by both function.

Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
Anand Jain 8714e458f1 btrfs-progs: subvol show: add support to search subvolume by rootid or uuid
Unless the top level is mounted there is no way to know the
details of all the subvolume.  For example:

mount -o subvol=sv1/newsv1 /dev/sdb /btrfs

btrfs su list /btrfs
ID 257 gen 12 top level 5 path sv1
ID 258 gen 9 top level 257 path sv1/snap
ID 259 gen 11 top level 257 path sv1/newsv1

You can't subvol show for sv1 and sv1/snap as its paths aren't
accessible to the user unless the its top level is mounted.

This patch adds two new options to the existing btrfs subvol show
cli. They are --rootid/-r or --uuid/-u, with this now the user will
be able to look for a subvolume using the rootid OR the uuid.

./btrfs su show -r 257 /btrfs
sv1
	Name: 			sv1
	UUID: 			30129358-c69d-3e4a-a662-29509cc69c95
	Parent UUID: 		-
	Received UUID: 		-
	Creation time: 		2017-07-11 20:32:57 +0800
	Subvolume ID: 		257
	Generation: 		12
	Gen at creation: 	7
	Parent ID: 		5
	Top level ID: 		5
	Flags: 			-
	Snapshot(s):
				sv1/snap

Signed-off-by: Anand Jain <anand.jain@oracle.com>
[ minor adjustments in the help text ]
Signed-off-by: David Sterba <dsterba@suse.com>
2017-07-20 17:43:43 +02:00
Qu Wenruo 5c8d747cc6 btrfs-progs: Refactor csum_tree_block to use btrfs_fs_info
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-07-12 17:52:41 +02:00
David Sterba 1ffcc9b455 btrfs-progs: move prefixcmp helper to utils
Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:47 +01:00
David Sterba bb104f5bce btrfs-progs: move message helpers out of utils
Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:46 +01:00
David Sterba a09f0e96e7 btrfs-progs: move utils code out of header
There are not performance critical static inlines, we can do the normal
declaration/definition split for various helpers.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:46 +01:00
David Sterba 1f739d73e3 btrfs-progs: convert: move internal bg size definition
Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:46 +01:00
David Sterba 11c83cefb8 btrfs-progs: move more mkfs declarations to the common header
Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:46 +01:00
David Sterba 14f9565c11 btrfs-progs: move fs features declarations to own header from utils
Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:45 +01:00
David Sterba 5f276edfda btrfs-progs: move convert definitions to own header
Create a header for filesystem conversion API, the config and the main
entry function.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:45 +01:00
David Sterba ad7c469ac3 btrfs-progs: move mkfs definitions to own header
Create a header for filesystem creation API, the config and the main
entry function.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:45 +01:00
David Sterba 50ac7b6dc8 btrfs-progs: move some common definitions to own header
Start a header for various defines that are supposed to be used in any
context or subpart.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:45 +01:00
David Sterba 1c880f34f1 btrfs-progs: move help defines to own header
Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:45 +01:00
Qu Wenruo a2203246ae btrfs-progs: Introduce kernel sizes to cleanup large intermediate number
Large numbers like (1024 * 1024 * 1024) may cost reader/reviewer to
waste one second to convert to 1G.

Introduce kernel include/linux/sizes.h to replace any intermediate
number larger than 4096 (not including 4096) to SZ_*.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:45 +01:00
David Sterba 95f515f2d1 btrfs-progs: introduce global config
Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:45 +01:00
David Sterba c855e60f7e btrfs-progs: mkfs/convert: separate the convert part from make_btrfs
The regulare mkfs_btrfs does not anything special about convert and just
passes the arguments. Make that two functions.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-01-27 12:20:43 +01:00
David Sterba 72ae343f77 btrfs-progs: make negative number pretty printing optional
Add a unit mode that will interpret the input number as a signed 64bit,
optionally and not by default for all numbers.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-01-25 09:47:32 +01:00
Zygo Blaxell 2f682fb89b btrfs-progs: utils: negative numbers are more plausible than sizes over 8 EiB
I got tired of seeing "16.00EiB" whenever btrfs-progs encounters a
negative size value, e.g. during resize:

Unallocated:
   /dev/mapper/datamd18   16.00EiB

This version is much more useful:

Unallocated:
   /dev/mapper/datamd18  -26.29GiB

Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-01-25 09:47:28 +01:00
David Sterba 49cb98e5d6 btrfs-progs: rename lookup_ino_rootid
It does not resolve the inode number but path where fd has been opened.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:28 +01:00
Karel Zak dcc3df7e6d btrfs-progs: rename btrfs_scan_lblkid() to btrfs_scan_devices()
It seems like bad idea to use a library name (lblkid) within generic
function name. The currently used scanning library is implementation
detail and this detail should be hidden for rest of the code.

Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2016-10-25 14:28:36 +02:00
David Sterba 508000138c btrfs-progs: mkfs: detect version of running kernel
Use the uname syscall and parse the string.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-25 14:28:36 +02:00
David Sterba 85d608f7ec btrfs-progs: constify string arguments where appropriate
Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-03 15:07:23 +02:00
David Sterba 2761c37d25 btrfs-progs: remove stray function declaration
Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-03 15:07:23 +02:00
David Sterba 7aaa1a92f6 btrfs-progs: mkfs: use preallocated buffers for config uuids
No need for dynamic allocation, the buffers are small, remove the
now-useless error conditions.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-21 13:44:24 +02:00
David Sterba 4241e27ee1 btrfs-progs: build: add more debugging features
Add options to show file and line or stack trace for error/warning
messages that use the common helpers. Possible to let any error stop
execution for ease of analysis and debugging.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-22 16:44:22 +02:00
David Sterba 5407ee85fc btrfs-progs: refactor and extend btrfs_prepare_device arguments
The message about discard is printed unconditionally and does not
conform to the --quite option eg. in mkfs. Consolidate the operation
flags into one argument and add support for verbosity.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-28 14:08:30 +02:00
David Sterba 18c6850fe1 btrfs-progs: new helper for option parsing, more permissive for "no options"
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-17 17:01:25 +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
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 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
Anand Jain 972cfbe32f btrfs-progs: fix re-declared get_device_info()
The other get_device_info() is in the same file, 4 lines above.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-02 14:41:47 +02:00
David Sterba 2a796d84af btrfs-progs: replace leafsize with nodesize
Nodesize is used in kernel, the values are always equal. We have to keep
leafsize in headers, similarly the tree setting functions still take and
set leafsize, but it's effectively a no-op.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-02 14:40:18 +02:00
David Sterba 41f6ae4820 btrfs-progs: rename __strncpy__null to __strncpy_null
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:26:33 +02:00
David Sterba 113d1ad49c btrfs-progs: cleanup block group helpers types
Use const char and remove stray prototypes.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:25:47 +02:00
David Sterba c1bb7a2d60 btrfs-progs: utils: make more arguments const
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:25:38 +02:00
Anand Jain 37288902fc btrfs-progs: rename get_subvol_name() to subvol_strip_mountpoint()
Signed-off-by: Anand Jain <anand.jain@oracle.com>
[ renamed from subvol_minus_mnt to subvol_strip_mountpoint ]
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:25:33 +02:00
Anand Jain e494f5790f btrfs-progs: create get_subvol_info()
get_subvol_info() is useful as we are adding more features around
subvolume. This function was inline with the function
cmd_subvol_show().

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:25:28 +02:00
Anand Jain 8cec21a7ed btrfs-progs: move get_subvol_name() to utils.c
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:25:23 +02:00
Anand Jain a5dbd2064e btrfs-progs: move test_issubvolume() to utils.c
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:25:13 +02:00
Ondrej Kozina 5d23b6a7b0 btrfs-progs: libbtrfs: remove max/min macros from API
kerncompat.h header file is part of libbtrfs API. min/max macros cause
conflict while building projects dependant on libbtrfs. Moving those
macros to btrfs-progs internal header file fixes the conflict.

Signed-off-by: Ondrej Kozina <okozina@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-14 13:42:47 +01:00
David Sterba a6cc8ea10a btrfs-progs: introduce helper for parsing args without options
All commands should support the "--" option separator. This is
transparently handled by getopt, but we don't use that everywhere.
Introduce a helper for commands that take no options (just the path).
The object file dependencies need to be adjusted a bit.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-14 11:07:10 +01:00
David Sterba 407f928cd2 btrfs-progs: add function attributes for the printf-like
Reported by gcc -Wsuggest-attribute=format .

Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-12 15:02:55 +01:00
Qu Wenruo 9c572c38a1 btrfs-progs: Introduce new members for btrfs_convert_context
Introduce 3 new members for btrfs_convert_context:

1) struct cache_tree used
Records accurate byte ranges which are used by old filesystem.
This will be used to create old filesystem image.

2) struct cache_tree data_chunks
Records batched ranges which must be covered by data chunks.
The bytenr range is optimized to meet all the chunk requirement.

3) u64 total_bytenr
Records how large the filesystem is in bytenr.
Yes, we can calculate it easy, but that's for old blocks based
filesystem.
This will make it more friendly for extent based filesystem.
And later cctx->block_counts and may be removed

And 2 for mkfs_config:
1) char *chunk_uuid.
Used as temporary chunk_uuid (unparsed) string for later
make_convert_btrfs()

2) u64 super_bytenr
Records the new temporary super bytenr after make_btrfs().

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-12 15:01:03 +01:00
Zhao Lei c1ff75db16 btrfs-progs: mkfs: allow --data DUP for single device
Current code don't support DUP profile on single device, except it
is in mixed mode, because of following reasons:

1: Some SSD do deduplication internally, so the duplication on
   the filesystem side has no effect.
2: On a physical device, if the entire disk broken, --data DUP does not
   help.
3: Half performance compared to single profile.
4: We have a workaround: create multi-partition on a single device,
   and btffs will treat them as multi device.

Instead of refusing --data DUP, we give the user a choice and print
a wrning.

Test:
1: Tested by xfstests
   Run with modified xfstests, I add test items of -d dup in single
   device into btrfs/* and common/rc, run tests of btrfs/*,
   with all mount option, no regression diffed with v4.3.
2: Tested by btrfs-progs
   Checked following commands in "-m dup -d dup" fs with memleck
   checking, all passed:
   mkfs.btrfs -f --data dup --metadata dup /dev/sda6
   btrfs filesystem show /dev/sda6
   btrfs filesystem label /dev/sda6 btrfs_label_test
   btrfs filesystem label /dev/sda6
   btrfs device scan --all-devices
   btrfs device scan /dev/sda6
   btrfs device scan /dev/sda6
   btrfs device ready /dev/sda6
   btrfs check /dev/sda6
   btrfs check -s 1 /dev/sda6
   btrfs check --repair /dev/sda6
   btrfs check --init-csum-tree /dev/sda6
   btrfs check --init-extent-tree /dev/sda6
   btrfs check --check-data-csum /dev/sda6
   btrfs check --qgroup-report /dev/sda6
   btrfs rescue super-recover -y /dev/sda6
   btrfs rescue zero-log /dev/sda6
   btrfs restore -l /dev/sda6
   btrfs restore /dev/sda6 /
   btrfs restore -s /dev/sda6 /
   btrfs restore -x /dev/sda6 /
   btrfs restore -m /dev/sda6 /
   btrfs restore -S /dev/sda6 /
   btrfs restore -v /dev/sda6 /
   btrfs restore -i /dev/sda6 /
   btrfs restore -o /dev/sda6 /
   btrfs restore -u0 /dev/sda6 /
   btrfs restore -u1 /dev/sda6 /
   btrfs restore -D /dev/sda6 /
   btrfs property list /dev/sda6
   btrfs property get /dev/sda6 label
   btrfs property set /dev/sda6 label test
   btrfs property set /dev/sda6 label btrfs_label_test
   btrfs help
   btrfs help --full
   btrfs version
   btrfsck /dev/sda6
   btrfs-find-root /dev/sda6
   btrfs-find-root -a /dev/sda6
   btrfs-map-logical -l1 /dev/sda6
   btrfs-map-logical -l1 -c1 /dev/sda6
   btrfs-map-logical -l1 -o /tmp/btrfs-map-logic-out /dev/sda6
   btrfs-map-logical -l1 -b1 /dev/sda6
   btrfs-select-super -s 0 /dev/sda6
   btrfs-select-super -s 1 /dev/sda6
   btrfstune -S 1 /dev/sda6
   btrfstune -f -S 0 /dev/sda6
   btrfstune -r /dev/sda6
   btrfstune -x /dev/sda6
   btrfstune -n /dev/sda6
   btrfstune -f -U 00000000-0000-0000-0000-000000000000 /dev/sda6
   btrfstune -f -u /dev/sda6
   btrfs-calc-size /dev/sda6
   btrfs-calc-size -v /dev/sda6
   btrfs-calc-size -b /dev/sda6
   btrfs-debug-tree /dev/sda6
   btrfs-debug-tree -e /dev/sda6
   btrfs-debug-tree -d /dev/sda6
   btrfs-debug-tree -r /dev/sda6
   btrfs-debug-tree -R /dev/sda6
   btrfs-debug-tree -u /dev/sda6
   btrfs-debug-tree -b 0 /dev/sda6
   btrfs-debug-tree -t 0 /dev/sda6
   btrfs-debug-tree -t 2 /dev/sda6
   btrfs-show-super /dev/sda6
   btrfs-show-super -i 0 /dev/sda6
   btrfs-show-super -i 1 /dev/sda6
   btrfs-show-super -i 2 /dev/sda6
   btrfs-show-super -a /dev/sda6
   btrfs-show-super -f /dev/sda6
   btrfs-show-super -F /dev/sda6
   btrfs subvolume list /mnt/btrfs-progs-tests
   btrfs subvolume create /mnt/btrfs-progs-tests/mysubvol
   btrfs subvolume list /mnt/btrfs-progs-tests
   btrfs subvolume get-default /mnt/btrfs-progs-tests
   btrfs subvolume set-default 258 /mnt/btrfs-progs-tests
   btrfs subvolume get-default /mnt/btrfs-progs-tests
   btrfs subvolume set-default  /mnt/btrfs-progs-tests
   btrfs subvolume snapshot /mnt/btrfs-progs-tests/mysubvol /mnt/btrfs-progs-tests/mysubvol_snap
   btrfs subvolume list /mnt/btrfs-progs-tests
   btrfs subvolume find-new /mnt/btrfs-progs-tests 0
   btrfs subvolume find-new /mnt/btrfs-progs-tests 0
   btrfs subvolume find-new /mnt/btrfs-progs-tests/mysubvol 0
   btrfs subvolume find-new /mnt/btrfs-progs-tests/mysubvol 0
   btrfs subvolume show /mnt/btrfs-progs-tests
   btrfs subvolume show /mnt/btrfs-progs-tests/mysubvol
   btrfs subvolume show /mnt/btrfs-progs-tests/mysubvol_snap
   btrfs subvolume sync /mnt/btrfs-progs-tests
   btrfs subvolume delete /mnt/btrfs-progs-tests/mysubvol_snap
   btrfs subvolume delete /mnt/btrfs-progs-tests/mysubvol
   btrfs subvolume sync /mnt/btrfs-progs-tests
   btrfs filesystem df /mnt/btrfs-progs-tests
   btrfs filesystem show /mnt/btrfs-progs-tests
   btrfs filesystem sync /mnt/btrfs-progs-tests
   btrfs filesystem label /mnt/btrfs-progs-tests btrfs_label_test
   btrfs filesystem label /mnt/btrfs-progs-tests
   btrfs filesystem usage /mnt/btrfs-progs-tests
   btrfs filesystem defragment -s 1024 -l 2048 /mnt/btrfs-progs-tests/filesystem_test_dir/test_dir_0/test_file_0
   btrfs filesystem defragment /mnt/btrfs-progs-tests/filesystem_test_dir/test_dir_0/test_file_1
   btrfs filesystem defragment -f /mnt/btrfs-progs-tests/filesystem_test_dir/test_dir_0/test_file_2
   btrfs filesystem defragment -czlib /mnt/btrfs-progs-tests/filesystem_test_dir/test_dir_0/test_file_3
   btrfs filesystem defragment -clzo /mnt/btrfs-progs-tests/filesystem_test_dir/test_dir_0/test_file_4
   btrfs filesystem defragment /mnt/btrfs-progs-tests/filesystem_test_dir
   btrfs filesystem defragment -r /mnt/btrfs-progs-tests/filesystem_test_dir
   btrfs filesystem defragment /mnt/btrfs-progs-tests
   btrfs filesystem resize 1:-10M /mnt/btrfs-progs-tests
   btrfs filesystem resize 1:max /mnt/btrfs-progs-tests
   btrfs balance start /mnt/btrfs-progs-tests
   btrfs balance start -v /mnt/btrfs-progs-tests
   btrfs balance start -f /mnt/btrfs-progs-tests
   btrfs balance status -v /mnt/btrfs-progs-tests
   btrfs balance pause /mnt/btrfs-progs-tests
   btrfs balance status /mnt/btrfs-progs-tests
   btrfs balance resume /mnt/btrfs-progs-tests
   btrfs balance status -v /mnt/btrfs-progs-tests
   btrfs balance cancel /mnt/btrfs-progs-tests
   btrfs balance start -dprofiles=single /mnt/btrfs-progs-tests
   btrfs balance start -dconvert=single /mnt/btrfs-progs-tests
   btrfs balance start -ddevid=1 /mnt/btrfs-progs-tests
   btrfs balance start -f -mprofiles=single /mnt/btrfs-progs-tests
   btrfs balance start -f -mconvert=single /mnt/btrfs-progs-tests
   btrfs balance start -f -mdevid=1 /mnt/btrfs-progs-tests
   btrfs balance start -f -sprofiles=single /mnt/btrfs-progs-tests
   btrfs balance start -f -sconvert=single /mnt/btrfs-progs-tests
   btrfs balance start -f -sdevid=1 /mnt/btrfs-progs-tests
   btrfs device add -f /dev/sda10 /mnt/btrfs-progs-tests
   btrfs device del /dev/sda10 /mnt/btrfs-progs-tests
   btrfs device stats /dev/sda6
   btrfs device stats -z /dev/sda6
   btrfs device stats /mnt/btrfs-progs-tests
   btrfs device stats -z /mnt/btrfs-progs-tests
   btrfs device usage /mnt/btrfs-progs-tests
   btrfs scrub status /mnt/btrfs-progs-tests
   btrfs scrub start -B /mnt/btrfs-progs-tests
   btrfs scrub start -B -d /mnt/btrfs-progs-tests
   btrfs scrub start -B -r /mnt/btrfs-progs-tests
   btrfs scrub status /mnt/btrfs-progs-tests
   btrfs scrub start /mnt/btrfs-progs-tests
   btrfs scrub status /mnt/btrfs-progs-tests
   btrfs scrub status /mnt/btrfs-progs-tests
   btrfs scrub status -d /mnt/btrfs-progs-tests
   btrfs scrub status -R /mnt/btrfs-progs-tests
   btrfs scrub status /mnt/btrfs-progs-tests
   btrfs scrub start /dev/sda6
   btrfs scrub status /dev/sda6
   btrfs scrub status /dev/sda6
   btrfs scrub status -d /dev/sda6
   btrfs scrub status -R /dev/sda6
   btrfs scrub status /dev/sda6
   btrfs subvolume snapshot -r /mnt/btrfs-progs-tests /mnt/btrfs-progs-tests/snap1
   btrfs send -f /tmp/btrfs_snapshot_test /mnt/btrfs-progs-tests/snap1
   btrfs send -e -f /tmp/btrfs_snapshot_test /mnt/btrfs-progs-tests/snap1
   btrfs send --no-data -f /tmp/btrfs_snapshot_test /mnt/btrfs-progs-tests/snap1
   btrfs quota enable /mnt/btrfs-progs-tests
   btrfs quota rescan /mnt/btrfs-progs-tests
   btrfs quota rescan -s /mnt/btrfs-progs-tests
   btrfs quota rescan -w /mnt/btrfs-progs-tests
   btrfs quota disable /mnt/btrfs-progs-tests
   btrfs quota enable /mnt/btrfs-progs-tests
   btrfs qgroup create 1/5 /mnt/btrfs-progs-tests
   btrfs qgroup create 2/5 /mnt/btrfs-progs-tests
   btrfs qgroup assign 1/5 2/5 /mnt/btrfs-progs-tests
   btrfs qgroup limit 1G 1/5 /mnt/btrfs-progs-tests
   btrfs qgroup show /mnt/btrfs-progs-tests
   btrfs qgroup show -p -c -r -e -F -f /mnt/btrfs-progs-tests
   btrfs qgroup remove 1/5 2/5 /mnt/btrfs-progs-tests
   btrfs qgroup destroy 2/5 /mnt/btrfs-progs-tests
   btrfs qgroup destroy 1/5 /mnt/btrfs-progs-tests
   btrfs quota disable /mnt/btrfs-progs-tests
   btrfs replace start -f -B /dev/sda6 /dev/sda10 /mnt/btrfs-progs-tests
   btrfs replace status /mnt/btrfs-progs-tests
   btrfs replace start -f -B /dev/sda10 /dev/sda6 /mnt/btrfs-progs-tests
   btrfs-convert /dev/sda6
   btrfs-convert -r /dev/sda6
   btrfs-convert -d /dev/sda6
   btrfs-convert -i /dev/sda6
   btrfs-convert -n /dev/sda6
   btrfs-convert -N 4096 /dev/sda6
   btrfs-convert -l test /dev/sda6
   btrfs-convert -L /dev/sda6
   btrfs-convert --no-progress /dev/sda6
   mkfs.btrfs -f /dev/sda6
   btrfs-image /dev/sda6 /tmp/btrfs_image.img
   btrfs-image -r /tmp/btrfs_image.img /dev/sda6
   mkfs.btrfs -f /dev/sda6
   btrfs-image -c 0 /dev/sda6 /tmp/btrfs_image.img
   btrfs-image -r /tmp/btrfs_image.img /dev/sda6
   mkfs.btrfs -f /dev/sda6
   btrfs-image -c 9 /dev/sda6 /tmp/btrfs_image.img
   btrfs-image -r /tmp/btrfs_image.img /dev/sda6
   mkfs.btrfs -f /dev/sda6
   btrfs-image -t 0 /dev/sda6 /tmp/btrfs_image.img
   btrfs-image -r /tmp/btrfs_image.img /dev/sda6
   mkfs.btrfs -f /dev/sda6
   btrfs-image -t 1 /dev/sda6 /tmp/btrfs_image.img
   btrfs-image -r /tmp/btrfs_image.img /dev/sda6
   mkfs.btrfs -f /dev/sda6
   btrfs-image -t 32 /dev/sda6 /tmp/btrfs_image.img
   btrfs-image -r /tmp/btrfs_image.img /dev/sda6
   mkfs.btrfs -f /dev/sda6
   btrfs-image -w /dev/sda6 /tmp/btrfs_image.img
   btrfs-image -r /tmp/btrfs_image.img /dev/sda6
   mkfs.btrfs -f /dev/sda6
   btrfs-image -w /dev/sda6 /tmp/btrfs_image.img
   btrfs-image -r /tmp/btrfs_image.img /dev/sda6
   btrfs-image -r -t 0 /tmp/btrfs_image.img /dev/sda6
   btrfs-image -r -t 1 /tmp/btrfs_image.img /dev/sda6
   btrfs-image -r -t 32 /tmp/btrfs_image.img /dev/sda6
   btrfs-image -r -o /tmp/btrfs_image.img /dev/sda6
3: Manual check relation source by:
   grep DUP *.c
   Confirmed that all source are modified.
4: Use this raid type manually, do some operations in fs,
   no error found in command and dmesg.
5: Combination of dup conversion with fsck
   Confirmed OK with relative kernel patch titled:
   [PATCH] btrfs: Support convert to -d dup for btrfs-convert

   export TEST_DEV='/dev/vdc'
   export TEST_DIR='/var/ltf/tester/mnt'

   do_dup_test()
   {
       local m_from="$1"
       local d_from="$2"
       local m_to="$3"
       local d_to="$4"

       echo "Convert from -m $m_from -d $d_from to -m $m_to -d $d_to"

       umount "$TEST_DIR" &>/dev/null
       ./mkfs.btrfs -f -m "$m_from" -d "$d_from" "$TEST_DEV" >/dev/null || return 1
       mount "$TEST_DEV" "$TEST_DIR" || return 1

       cp -a /sbin/* "$TEST_DIR"

       [[ "$m_from" != "$m_to" ]] && {
           ./btrfs balance start -f -mconvert="$m_to" "$TEST_DIR" || return 1
       }

       [[ "$d_from" != "$d_to" ]] && {
       local opt=()
           [[ "$d_to" == single ]] && opt+=("-f")
           ./btrfs balance start "${opt[@]}" -dconvert="$d_to" "$TEST_DIR" || return 1
       }

       umount "$TEST_DIR" || return 1
       ./btrfsck "$TEST_DEV" || return 1
       echo

       return 0
   }

   test_all()
   {
       for m_from in single dup; do
       for d_from in single dup; do
       for m_to in single dup; do
       for d_to in single dup; do
       do_dup_test "$m_from" "$d_from" "$m_to" "$d_to" || return 1
       done
       done
       done
       done
   }

   test_all

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Tested-by: Austin S. Hemmelgarn <ahferroin7@gmail.com>
[ minor updates in the changelog ]
Signed-off-by: David Sterba <dsterba@suse.com>
2015-11-26 15:58:38 +01:00