convert-tests now test both 4096 and 16384 nodesizes.
Signed-off-by: Sebastian Thorarensen <sebth@naju.se>
Signed-off-by: David Sterba <dsterba@suse.cz>
Allow btrfs-convert to use nodesizes other than 4096. It defaults to
max(16384, pagesize), like mkfs.
Signed-off-by: Sebastian Thorarensen <sebth@naju.se>
Signed-off-by: David Sterba <dsterba@suse.cz>
check_node_or_leaf_size in utils.c now prints 'nodesize (or leafsize)'
instead of 'leafsize (or nodesize)' in the error messages, in order to
be less confusing for the user, as leafsize in mkfs is deprecated.
'ERROR: ' is also prepended to be consistent with other error messages.
Signed-off-by: Sebastian Thorarensen <sebth@naju.se>
Signed-off-by: David Sterba <dsterba@suse.cz>
Move the constant DEFAULT_MKFS_LEAF_SIZE to utils.h and rename it to
BTRFS_MKFS_DEFAULT_NODE_SIZE for consistency. Move the function
check_leaf_or_node_size to utils.c and rename it to
btrfs_check_node_or_leaf_size.
Signed-off-by: Sebastian Thorarensen <sebth@naju.se>
[added btrfs_ prefix]
Signed-off-by: David Sterba <dsterba@suse.cz>
The total size of devices was summed from raw partition size which is
wrong in two ways:
- if the device is missing, the size is 0 and it mismatches the size
summed from chunks, leading to bogus numbers like
Device unallocated: 16.00EiB
Used: 1.88TiB
Free (estimated): 8.00EiB (min: 8.00EiB)
- we should really account the device size that's occupied by btrfs, not
the real partition size altough it's the same most of the time
The sum of missing devices is now printed in the summary and any missing
device path is replaced with 'missing' instead of blank:
Data,RAID1: Size:972.00GiB, Used:962.15GiB
972.00GiB
/dev/sdb1 972.00GiB
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=94911
Reported-by: <raffix@web.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
The macro is in a public header and breaks build of some applications.
Signed-off-by: Lokesh Mandvekar <lsm5@fedoraproject.org>
[edit changelog]
Signed-off-by: David Sterba <dsterba@suse.cz>
Although fsck-test/012 uses sudo, it uses 'sudo -n', which won't prompt
user to input password and will return 1 if no valid credential is
found.
And this makes test result quite annoying since it fails to mount and
still continue, which will always fail.
This patch will check 'sudo -v -n' and 'sudo -n true' to determine
whether sudo works fine in different version/settings, since in some
setting/version, 'sudo -v -n' will fail even the user is set NOPASSWD.
Also, remove the 'have_root_helper' variant, since there is a
possibility that sudo credential will timeout during the test and
'have_root_helper' won't help to detect such problem.
New '_sudo' command will do credential check if needed to avoid such
problem.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
With progress turned on by default we should be able to disable it
as well.
Reported-by: Jérôme Poulin <jeromepoulin@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Unlike kernel, these functions in userland just test/set/clear a member.
So move them to header to avoid extra function call cost.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Before this patch, csum tree rebuild will not work with extent tree
rebuild, since extent tree rebuild will only build up basic block
groups, but csum tree rebuild needs data extents to rebuild.
So if one use btrfsck with --init-csum-tree and --init-extent-tree, csum
tree will be empty and tons of "missing csum" error will be outputted.
This patch allows csum tree rebuild get its data from fs/subvol trees
using regular file extents (which is also the only one using csum tree
currently).
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[renamed to fill_csum_tree_from_one_fs_root]
Signed-off-by: David Sterba <dsterba@suse.cz>
The return values 12 and 13 are not used spectially except as return
value. No description and definition about them. so I change them to
generic errno.
Signed-off-by: Fan Chengniang <fancn.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Agreed by several people, showing progress by default makes sense as
conversion is a one-time and long running action.
Signed-off-by: David Sterba <dsterba@suse.cz>
There is a case that can cause nlink fix function.
For example, lost+found dir already has the following files:
---------------------------
|ino |filename |
|-------------------------|
|258 |normal_file |
|259 |normal_file.260 |
---------------------------
The next inode to be fixed is the following:
---------------------------
|260 |normail_file |
---------------------------
And when trying to move inode to lost+found dir, its file name conflicts
with inode 258, and even add ".INO" suffix, it still conflicts with
inode 259.
Since the move failed, the LINK_COUNT_ERR flag is not cleared, the inode
record will not be freed, btrfsck will try fix it again and again,
causing the infinite loop.
The patch will first change the ".INO" suffix naming to a loop behavior,
and clear the LINK_COUNT_ERR flag anyway to avoid infinite loop.
Reported-by: Naohiro Aota <naota@elisp.net>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
The PACKAGE_URL is set from optional parameter of AC_INIT starting in
autoconf 2.64. There are enterprise distros with version 2.63, we can
make the build work there easily as well.
Fixes build failure:
mkfs.c: In function ?main?:
mkfs.c:1492: error: ?PACKAGE_URL? undeclared (first use in this function)
Reported-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
There are 2 known extent buffer leaks:
1) With -t option.
-t option will skip other tree roots, but it will read the root node
first and then skip it.
Where it forgets to free the tree block it read.
2) with -b option.
It forgets to free the tree block it read.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Same thing as clang cleanup patch commit 040b3f11ba
"btrfs-progs: Makefile: Move linker only option to LDFLAGS"
But the move to autoconfig seems using old Makefile.
So do it again.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Add option '-a' for btrfs-find-root to iterate all the metadata extents
even the root is already found.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Since we switched to new open_ctree flag and new find-root facility,
there is no need to keep the old find-root codes.
Clean it up.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Since the new find-root infrastructure is here with better root
judgement with less codes, just switch to it.
To switch to the new infrastructure, new print function is added and
output format is slighted changed.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Before the patch, btrfs-find-root will only consider it find a good root
if its generation matches generation in superblock and its level is
currently found highest level.
But that's not correct in 2 ways.
1) Root with decreased level
Since tree level can decrease, like subvolume/file deletion.
Which will make the new root have higher generation but lower level.
2) Root not updated in latest transaction.
If there is some root not updated in latest transaction, its generation
will be smaller than the one in superblock, and btrfs-find-root will not
find it.
This patch will use different generation for different tree to search,
solving the above problems.
Currently, it only supports generation/level in superblock. Using tree
root level/generation if possible will be introduced later.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Since in previous patches, we introduced the new open_ctree flag
OPEN_CTREE_CHUNK_ROOT_ONLY, switch btrfs-find-root to use it instead of
the open_ctree_broken().
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Introduce new find-root.[ch] infrastructure which has better tree root
judgment and uses much less codes to do it.
The new infrastructure will only record tree blocks with highest level
among its generation, and do better judgment whether the found tree block
is the desired one(level + generation check other than the original
generation only check).
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Add new flag CHUNK_ONLY and internal used only flag __RETURN_CHUNK.
CHUNK_ONLY will imply __RETURN_CHUNK, SUPPRESS_ERROR and PARTIAL, which
will allow the fs to be opened with only chunk tree OK.
This will improve the usability for btrfs-find-root.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Add new open ctree flag OPEN_CTREE_SUPPRESS_CHECK_BLOCK_ERRORS to
suppress tree block csum error output.
Provides the basis for new btrfs-find-root and other enhancement on
btrfs offline tools output.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[renamed vars and funcs, added comments]
Signed-off-by: David Sterba <dsterba@suse.cz>
Before this patch, check_tree_block() will print error on bytenr
mismatch but don't output error on fsid mismatch.
This patch will modify check_tree_block(), so it will only return errno
but not print error messages.
The error message will be output by print_tree_block_err() function.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[renamed and cleaned return codes]
Signed-off-by: David Sterba <dsterba@suse.cz>
"This series of patches fixes up btrfsck in lots of ways and adds some
new functionality. These patches were required to fix Hugo's broken
multi-disk fs as well as fix fsck so it would actually pass all of the
fsck tests. This also fixes a long standing btrfs-image problem where
it wouldn't restore multi disk images onto a single disk properly."
We can have FULL_BACKREF set or not set when we need the opposite, this patch
fixes this problem by setting a bit when the flag is set improperly. This way
we can either correct the problem when we re-create the extent item if the
backrefs are also wrong, or we can just set the flag properly in the extent
item. Thanks,
Signed-off-by: Josef Bacik <jbacik@fb.com>
When we go to fixup the dev items after a restore we scan all existing devices.
If you happen to be a btrfs developer you could possibly open up some random
device that you didn't just restore onto, which gives you weird errors and makes
you super cranky and waste a day trying to figure out what is failing. This
will make it so that we use the fd we've already opened for opening our ctree.
Thanks,
Signed-off-by: Josef Bacik <jbacik@fb.com>
Currently btrfs-debug-tree ignores the FULL_BACKREF flag which makes it hard to
figure out problems related to FULL_BACKREF. Thanks,
Signed-off-by: Josef Bacik <jbacik@fb.com>
When we restore a multi disk image onto a single disk we need to update the dev
items used and total bytes so that fsck doesn't freak out and that we get normal
results from stuff like btrfs fi show. Thanks,
Signed-off-by: Josef Bacik <jbacik@fb.com>
We don't want to keep extent records pinned down if we fix stuff as we may need
the space and we can be pretty sure that these records are correct. Thanks,
Signed-off-by: Josef Bacik <jbacik@fb.com>
We hold a transaction open for the entirety of fixing extent refs. This works
out ok most of the time but we can be tight on space and run out of space when
fixing things. To get around this just push down the transaction starting dance
into the functions that actually fix things. This keeps us from ending up with
ENOSPC because we pinned everything and allows the code to be a bit simpler.
Thanks,
Signed-off-by: Josef Bacik <jbacik@fb.com>
Hitting enospc problems with a really corrupt fs uncovered the fact that we
match any flag in a block group when creating space info's. This is a problem
if we have a raid level set, we'll end up with only one space info that covers
metadata and data because they share a raid level. We don't want this, we want
to separate out the data and metadata space infos, so mask off the raid level
and only use the main flags. Thanks,
Signed-off-by: Josef Bacik <jbacik@fb.com>
The METADUMP super flag makes us skip doing the chunk tree reading which isn't
helpful for the new restore since we have a valid chunk tree. But we still want
to have a way for the kernel to know that this is a metadump restore so it
doesn't do things like verify data checksums. We also want to skip some of the
device extent checks in fsck since those will obviously not match. Thanks,
Signed-off-by: Josef Bacik <jbacik@fb.com>
For some reason we only allow btrfs-image restore to have one thread, which is
incredibly slow with large images. So allow us to do work with more than just
one thread. This made my restore go from 16 minutes to 3 minutes. Thanks,
Signed-off-by: Josef Bacik <jbacik@fb.com>