Commit Graph

4148 Commits (de34a33a8204af9e675e5247c88eb727955beae1)
 

Author SHA1 Message Date
Qu Wenruo 2615aca92c btrfs-progs: ctree: Add extra level check for read_node_slot()
Strangely, we have level check in btrfs_print_tree() while we don't have
the same check in read_node_slot().

That's to say, for the following corruption, btrfs_search_slot() or
btrfs_next_leaf() can return invalid leaf:

Parent eb:
  node XXXXXX level 1
              ^^^^^^^
              Child should be leaf (level 0)
  ...
  key (XXX XXX XXX) block YYYYYY

Child eb:
  leaf YYYYYY level 1
              ^^^^^^^
              Something went wrong now

And for the corrupted leaf returned, later caller can be screwed up
easily.

Reported-by: Ralph Gauges <ralphgauges@googlemail.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:54 +02:00
David Sterba e875cd98e3 btrfs-progs: tests: fix source path for testsuite
The commit cebf3b3722 ("btrfs-progs: introduce TEST_TOP and
INTERNAL_BIN for tests") did not convert all test paths. This would
break the exported testsutie.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:54 +02:00
Qu Wenruo 546cea6f36 btrfs-progs: tests: Add test case with valid orphan inode
Regression test for false alerts in lowmem mode.

Signed-off-by: Qu Wenruo <wqu@suse.com>
[ update test ]
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:54 +02:00
Qu Wenruo 8d6c444782 btrfs-progs: check: lowmem: Fix false alert about orphan inode
Btrfs can delay inode deletion and in that case btrfs will unlink the
victim inode from its parent dir, and insert a marker to info btrfs to
delete it later.

In that case, such victim inode will have nlinks == 0, but is still
completely valid.
Original mode won't report such problem, but lowmem mode doesn't check
the ORPHAN_ITEM key for such inode, and can report false alert like:
------
ERROR: root 257 INODE[28891726] is orphan item
------

Fix such false alert by checking orphan item for inode whose nlink is 0.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:54 +02:00
Qu Wenruo 89f5a8f97c btrfs-progs: gitignore: Ignore patches
Although it's not a good practice to format all patches under project
directory, sometimes lazy bones like me just like to put patches under
project directory.

Just ignore such patches.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:54 +02:00
Qu Wenruo 4affb86542 btrfs-progs: gitignore: Ignore *.restored test image
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:53 +02:00
Lu Fengqi 0155481cc9 btrfs-progs: fsck-tests: Introduce test case with keyed data backref with the extent offset
Add the testcase for false alert of data extent backref lost with the
extent offset.

The image can be reproduced by the following commands:
------
dev=~/test.img
mnt=/mnt/btrfs

umount $mnt &> /dev/null
fallocate -l 128M $dev

mkfs.btrfs $dev
mount $dev $mnt

for i in `seq 1 10`; do
	xfs_io -f -c "pwrite 0 2K" $mnt/file$i
done

xfs_io -f -c "falloc 0 64K" $mnt/file11

for i in `seq 1 32`; do
	xfs_io -f -c "reflink $mnt/file11 0 $(($i * 64))K 64K" $mnt/file11
done

xfs_io -f -c "reflink $mnt/file11 32K $((33 * 64))K 32K" $mnt/file11

btrfs subvolume snapshot $mnt $mnt/snap1

umount $mnt
btrfs-image -c9 $dev extent_data_ref.img
------

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:53 +02:00
Lu Fengqi 905b3d18ae btrfs-progs: check/lowmem: Fix false alert of data extent backref lost for snapshot
Btrfs lowmem check reports the following false alert:
------
ERROR: file extent[267 2162688] root 256 owner 5 backref lost
------

The file extent is in the leaf which is shared by file tree 256 and fs
tree.
------
leaf 30605312 items 46 free space 4353 generation 7 owner 5
......
        item 45 key (267 EXTENT_DATA 2162688) itemoff 5503 itemsize 53
                generation 7 type 2 (prealloc)
                prealloc data disk byte 13631488 nr 65536
                prealloc data offset 32768 nr 32768
------

And there is the corresponding extent_data_ref item in the extent tree.
------
        item 1 key (13631488 EXTENT_DATA_REF 1007496934287921081) itemoff 15274 itemsize 28
                extent data backref root 5 objectid 267 offset 2129920 count 1
------

The offset of EXTENT_DATA_REF which is the hash of the owner root objectid,
the inode number and the calculated offset (file offset - extent offset).

What caused the false alert is the code mix up the owner root objectid and
the file tree objectid.

Fixes: b0d360b541 ("btrfs-progs: check: introduce function to check data backref in extent tree")
Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:53 +02:00
Lu Fengqi 634e73e9d3 btrfs-progs: check/lowmem: Fix the incorrect error message of check_extent_data_item
Instead of the disk_bytenr and disk_num_bytes of the extent_item which the
file extent references, we should output the objectid and offset of the
file extent. And the leaf may be shared by the file trees, we should print
the objectid of the root and the owner of the leaf.

Fixes: b0d360b541 ("btrfs-progs: check: introduce function to check data backref in extent tree")
Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:53 +02:00
Qu Wenruo 14bf2b546d btrfs-progs: dump-super: Don't verify csum if csum type or size is unknown
Reported-by: Ken Swenson <flat@imo.uto.moe>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:53 +02:00
Qu Wenruo 4c7094e046 btrfs-progs: free-space-cache: Enhance free space cache free space check
When we found free space difference between free space cache and block
group item, we just discard this free space cache.

Normally such difference is caused by btrfs_reserve_extent() called by
delalloc which is out of a transaction.
And since all btrfs_release_extent() is called with a transaction, under
heavy race free space cache can have less free space than block group
item.

Normally kernel will detect such difference and just discard that cache.

However we must be more careful if free space cache has more free space
cache, and if that happens, paried with above race one invalid free
space cache can be loaded into kernel.

So if we find any free space cache who has more free space then block
group item, we report it as an error other than ignoring it.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:53 +02:00
David Sterba fd5767a574 btrfs-progs: docs: add section about filesystem limits to btrfs(5)
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:53 +02:00
Qu Wenruo bb338fb0f0 btrfs-progs: free-space-cache: Use DIV_ROUND_UP() to replace open code
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:53 +02:00
Omar Sandoval f44a055012 libbtrfsutil: use pkg-config detection for the right Python version
The user may have specified a different version of Python than the
python3 from their $PATH (e.g., with PYTHON=/usr/bin/python3.6).

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:53 +02:00
David Sterba 58b5610845 btrfs-progs: ci: enable clang and python for musl build test
The updated image now provides clang, so the variable is exported from
the base environment to docker. And we have python too.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:38 +01:00
David Sterba 58720c6441 btrfs-progs: ci: update test image packages - add clang and python
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:38 +01:00
David Sterba 58fae8ff58 libbtrfsutils: add python-devel detection
Use pkg-config to detect python devel.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:38 +01:00
David Sterba efc08d3390 btrfs-progs: ci: cache built dependencies
For a slight speed up of the build, cache reiserfs and zstd. A quick
cache validity is done, or it can be cleared manually on travis web UI.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:38 +01:00
Omar Sandoval f0a376df47 btrfs-progs: replace test_issubvolume() with btrfs_util_is_subvolume()
This gets the remaining occurrences that weren't covered by previous
conversions.

Signed-off-by: Omar Sandoval <osandov@fb.com>
[ fixup test_issubvolume due to removed dependency patch ]
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:38 +01:00
Omar Sandoval bbf7acbef0 btrfs-progs: use libbtrfsutil for subvol sync
btrfs_util_f_deleted_subvolumes() replaces enumerate_dead_subvols() and
btrfs_util_f_subvolume_info() replaces is_subvolume_cleaned().

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:37 +01:00
Omar Sandoval 9005b603d7 btrfs-progs: use libbtrfsutil for subvol show
Now implemented with btrfs_util_subvolume_path(),
btrfs_util_subvolume_info(), and subvolume iterators.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:37 +01:00
Omar Sandoval afb0426016 btrfs-progs: use libbtrfsutil for subvol delete
Most of the interesting part of this command is the commit mode, so this
only saves a little bit of code.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:37 +01:00
Omar Sandoval 9e73a416f0 btrfs-progs: use libbtrfsutil for get-default
The only thing of note here is the "top level" column. This used to mean
something else, but for a long time it has been equal to the parent ID.
I preserved this for backwards compatability.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:37 +01:00
Omar Sandoval 2116398b1d btrfs-progs: use libbtrfsutil for set-default
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:37 +01:00
Omar Sandoval ec7251486d btrfs-progs: use libbtrfsutil for sync ioctls
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:37 +01:00
Omar Sandoval 3e76e9b676 btrfs-progs: use libbtrfsutil for read-only property
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:37 +01:00
Omar Sandoval f239180162 libbtrfsutil: add btrfs_util_deleted_subvolumes()
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:37 +01:00
Omar Sandoval 678da5a7f7 libbtrfsutil: add btrfs_util_delete_subvolume()
We also support recursive deletion using a subvolume iterator.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:37 +01:00
Omar Sandoval cfa89b3082 libbtrfsutil: add btrfs_util_create_snapshot()
Thanks to subvolume iterators, we can also implement recursive snapshot
fairly easily.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:37 +01:00
Omar Sandoval 0b8512b7f5 libbtrfsutil: add subvolume iterator helpers
This is how we can implement stuff like `btrfs subvol list`. Rather than
producing the entire list upfront, the iterator approach uses less
memory in the common case where the whole list is not stored (O(max
subvolume path length)). It supports both pre-order traversal (useful
for, e.g, recursive snapshot) and post-order traversal (useful for
recursive delete).

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:37 +01:00
David Sterba e0d173c6c4 libbtrfsutil: add stub for reallocarray
This function is new in glibc 2.26 and breaks build in CI and possibly
other environments.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:37 +01:00
Omar Sandoval 624e0233e0 libbtrfsutil: add btrfs_util_[gs]et_default_subvolume()
set_default_subvolume() is a trivial ioctl(), but there's no ioctl() for
get_default_subvolume(), so we need to search the root tree.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:36 +01:00
Omar Sandoval 172c0d1a12 libbtrfsutil: add btrfs_util_[gs]et_read_only()
In the future, btrfs_util_[gs]et_subvolume_flags() might be useful, but
since these are the only subvolume flags we've defined in all this time,
this will do for now.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:36 +01:00
Omar Sandoval 0d36261bd5 libbtrfsutil: add btrfs_util_subvolume_info()
This gets the the information in `btrfs subvolume show` from the root
item.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:36 +01:00
Omar Sandoval 8b87811f94 libbtrfsutil: add btrfs_util_subvolume_path()
We can just walk up root backrefs with BTRFS_IOC_TREE_SEARCH and inode
paths with BTRFS_IOC_INO_LOOKUP.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:36 +01:00
Omar Sandoval f676a8ad11 libbtrfsutil: add btrfs_util_create_subvolume()
Doing the ioctl() directly isn't too bad, but passing in a full path is
more convenient than opening the parent and passing the path component.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:36 +01:00
Omar Sandoval 92d4035074 libbtrfsutil: add btrfs_util_is_subvolume() and btrfs_util_subvolume_id()
These are the most trivial helpers in the library and will be used to
implement several of the more involved functions.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:36 +01:00
Omar Sandoval 1b2775bdb0 libbtrfsutil: copy in Btrfs UAPI headers
Systems with older kernels won't have these available, and the copies in
btrfs-progs aren't quite compatible, so for now, let's just copy these
in. We can potentially deduplicate some of this in the future.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:36 +01:00
Omar Sandoval 71d135ef44 libbtrfsutil: fix Python tests
These were broken when the patch series got shuffled around.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:36 +01:00
Qu Wenruo 2ac42077c2 btrfs-progs: Move chunk stripe size calculation function to volumes.h
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:26 +01:00
Qu Wenruo f174972d2d btrfs-progs: volumes: Allow find_free_dev_extent() to return maximum hole size
Just as kernel find_free_dev_extent(), allow it to return maximum hole
size for us to build device list for later chunk allocator rework.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-24 01:37:17 +01:00
Qu Wenruo 12becfe122 btrfs-progs: Introduce btrfs_raid_array and related infrastructures
As part of the effort to unify code and behavior between btrfs-progs and
kernel, copy the btrfs_raid_array from kernel to btrfs-progs.

So later we can use the btrfs_raid_array[] to get needed raid info other
than manually do if-else branches.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-24 01:37:17 +01:00
Qu Wenruo e9097ad593 btrfs-progs: Refactor parameter of BTRFS_MAX_DEVS() from root to fs_info
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-24 01:37:17 +01:00
Omar Sandoval 9615c23d15 libbtrfsutil: add filesystem sync helpers
Namely, sync, start_sync, and wait_sync.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-24 01:37:17 +01:00
Omar Sandoval bad4208da3 libbtrfsutil: add qgroup inheritance helpers
We want to hide struct btrfs_qgroup_inherit from the user because that
comes from the Btrfs UAPI headers. Instead, wrap it in a struct
btrfs_util_qgroup_inherit and provide helpers to manipulate it. This
will be used for subvolume and snapshot creation.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-24 01:37:17 +01:00
Omar Sandoval 23c01b3c1b libbtrfsutil: add Python bindings
The C libbtrfsutil library isn't very useful for scripting, so we also
want bindings for Python. Writing unit tests in Python is also much
easier than doing so in C. Only Python 3 is supported; if someone really
wants Python 2 support, they can write their own bindings. This commit
is just the scaffolding.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-24 01:37:17 +01:00
David Sterba d51e8b128f btrfs-progs: ci: add python dependencies for libbtrfsutil
Install the setuptools. Python is not yet in the musl image, so the
build is disabled there.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-24 01:37:17 +01:00
Omar Sandoval 502e2a3510 Add libbtrfsutil
Currently, users wishing to manage Btrfs filesystems programatically
have to shell out to btrfs-progs and parse the output. This isn't ideal.
The goal of libbtrfsutil is to provide a library version of as many of
the operations of btrfs-progs as possible and to migrate btrfs-progs to
use it.

Rather than simply refactoring the existing btrfs-progs code, the code
has to be written from scratch for a couple of reasons:

* A lot of the btrfs-progs code was not designed with a nice library API
  in mind in terms of reusability, naming, and error reporting.
* libbtrfsutil is licensed under the LGPL, whereas btrfs-progs is under
  the GPL, which makes it dubious to directly copy or move the code.

Eventually, most of the low-level btrfs-progs code should either live in
libbtrfsutil or the shared kernel/userspace filesystem code, and
btrfs-progs will just be the CLI wrapper.

This first commit just includes the build system changes, license,
README, and error reporting helper.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Reviewed-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-24 01:37:16 +01:00
David Sterba 510bb4ccc4 btrfs-progs: tests: add helper to log pipe stdout
Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-19 19:24:07 +01:00
David Sterba ea0956bb2a btrfs-progs: tests: add test for send -p on 2 mont points
Add testcase from issue, use reproducer from Axel Burri.

Issue: #96
Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-19 19:07:32 +01:00