Currently, balance operations are run synchronously in the foreground.
This is nice for interactive management, but is kind of crappy when you
start looking at automation and similar things.
This patch adds an option to `btrfs balance start` to tell it to
daemonize prior to running the balance operation, thus allowing us to
preform balances asynchronously. The two biggest use cases I have for
this are starting a balance on a remote server without establishing a
full shell session, and being able to background the balance in a
recovery shell (which usually has no job control) so I can still get
progress information.
Because it simply daemonizes prior to calling the balance ioctl, this
doesn't actually need any kernel support.
Signed-off-by: Austin S. Hemmelgarn <ahferroin7@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Copy le_test_bit() from the kernel and use that for the free space tree
bitmaps.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
I have a valid btrfs image which contains,
...
item 10 key (1103101952 BLOCK_GROUP_ITEM 1288372224) itemoff 15947 itemsize 24
block group used 655360 chunk_objectid 256 flags DATA|RAID5
item 11 key (1103364096 EXTENT_ITEM 131072) itemoff 15894 itemsize 53
extent refs 1 gen 11 flags DATA
extent data backref root 5 objectid 258 offset 0 count 1
item 12 key (1103888384 EXTENT_ITEM 262144) itemoff 15841 itemsize 53
extent refs 1 gen 15 flags DATA
extent data backref root 1 objectid 256 offset 0 count 1
item 13 key (1104281600 EXTENT_ITEM 262144) itemoff 15788 itemsize 53
extent refs 1 gen 15 flags DATA
extent data backref root 1 objectid 257 offset 0 count 1
...
The extent [1103364096, 131072) has length 131072, but if we run
"btrfs-map-logical -l 1103364096 -b $((65536 * 3)) /dev/sda"
it will return mapping info 's of non-existing extents.
It's because it assumes that extents's are contiguous on logical address,
when it's not true, after one loop (cur_logical += cur_len) and mapping
the next extent, we can get an extent that is out of our search range and
we end up with a negative @real_len and printing all mapping infos till
the disk end.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
'btrfs file du' is a very useful tool to watch my system
file usage information with snapshot aware.
when trying to run following commands:
[root@localhost btrfs-progs]# btrfs file du /
Total Exclusive Set shared Filename
ERROR: Failed to lookup root id - Inappropriate ioctl for device
ERROR: cannot check space of '/': Unknown error -1
and My Filesystem looks like this:
[root@localhost btrfs-progs]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 16G 0 16G 0% /dev
tmpfs tmpfs 16G 368K 16G 1% /dev/shm
tmpfs tmpfs 16G 1.4M 16G 1% /run
tmpfs tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/sda3 btrfs 60G 19G 40G 33% /
tmpfs tmpfs 16G 332K 16G 1% /tmp
/dev/sdc btrfs 2.8T 166G 1.7T 9% /data
/dev/sda2 xfs 2.0G 452M 1.6G 23% /boot
/dev/sda1 vfat 1.9G 11M 1.9G 1% /boot/efi
tmpfs tmpfs 3.2G 24K 3.2G 1% /run/user/1000
So I installed Btrfs as my root partition, but boot partition
can be other fs.
We can Let btrfs tool aware of this is not a btrfs file or
directory and skip those files, so that someone like me
could just run 'btrfs file du /' to scan all btrfs filesystems.
After patch, it will look like:
Total Exclusive Set shared Filename
0.00B 0.00B - //root/.bash_logout
0.00B 0.00B - //root/.bash_profile
0.00B 0.00B - //root/.bashrc
0.00B 0.00B - //root/.cshrc
0.00B 0.00B - //root/.tcshrc
This works for me to analysis system usage and analysis
performaces.
Signed-off-by: Wang Shilong <wangshilong1991@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
When open in btrfs_open_devices failed, only the following message is
displayed. Therefore the user doesn't understand the reason why open
failed.
# btrfs check /dev/sdb8
Couldn't open file system
This patch adds the error message when open fails.
Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
If btrfs isn't in the path, this test will fail with:
[TEST/misc] 006-image-on-missing-device
failed: btrfs fi show /dev/loop0
test failed for case 006-image-on-missing-device
Makefile:226: recipe for target 'test-misc' failed
make: *** [test-misc] Error 1
Fix the test script by adding $TOP to the path.
Signed-off-by: Luis Henriques <henrix@camandro.org>
[ updated to full command names ]
Signed-off-by: David Sterba <dsterba@suse.com>
Now that we can verify all qgroups, we can write the corrected qgroups out
to disk when '--repair' is specified. The qgroup status item is also updated
to clear any out-of-date state. The repair_ functions were modeled after the
inode repair code in cmds-check.c.
I also renamed the 'scan' member of qgroup_status_item to 'rescan' in order
to keep consistency with the kernel.
Testing this was easy, I just reproduced qgroup inconsistencies via the
usual routes and had btrfsck fix them.
Signed-off-by: Mark Fasheh <mfasheh@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
At the moment we only check subvolume quota groups (level 0). With this
patch we can check groups above 0, thus verifying the entire qgroup
hierarchy on a file system. The accounting portion of this patch is modeled
after the kernel - we are essentially reimplementing the 'quota rescan' case
here. Most other sections of this code went unchanged, in particular the
root counting works independently of the accounting.
Signed-off-by: Mark Fasheh <mfasheh@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
We now have two data structures that can be used to iterate the same data
set, and there may be quite a few of them in memory. Eliminating the
list_head member will reduce memory consumption while iterating over
the extent backrefs.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
For the pathlogical case, like xfstests generic/297 that creates a
large file consisting of one, repeating reflinked extent, fsck can
take hours. The root cause is that calling find_data_backref while
iterating the extent records is an O(n^2) algorithm. For my
example test run, n was 2*2^20 and fsck was at 8 hours and counting.
This patch supplements the list with an rbtree and drops the runtime
of that testcase to about 20 seconds.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
We either open code list_entry calls or outright cast between types. The
compiler will do the right thing if we use static inlines to do
typesafe conversions.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
BTRFS_IOC_LOGICAL_INO takes a btrfs_ioctl_logical_ino_args as argument,
not a btrfs_ioctl_ino_path_args. The lines were probably copy/pasted
when the code was written.
Since btrfs_ioctl_logical_ino_args and btrfs_ioctl_ino_path_args have
the same size, the actual IOCTL definition here does not change.
But, it makes the code less confusing for the reader.
Signed-off-by: Hans van Kranenburg <hans.van.kranenburg@mendix.com>
Signed-off-by: David Sterba <dsterba@suse.com>
When cleanup_temp_chunks() removes block groups, it forgot to update
mkfs_allocation accordingly, fix this.
Signed-off-by: Wang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
[ minor adjustments ]
Signed-off-by: David Sterba <dsterba@suse.com>
For ext* fs containing a large hole(larger than 128M), btrfs-convert
will only insert one 128M hole extent and skip the remaining.
This leads to discontinuous file extents.
Add test case for it, and since it's a pinpoint regression test case, no
combination of convert options nor checksum verification.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Btrfs_record_file_extent() will split extents using max extent size(128M).
It works well for real file extents, but not that well for large
hole extent, as hole doesn't have extent size limit.
In that case, it will only insert one 128M hole, and skip the rest,
leading to discontinuous extent error for converted btrfs.
Fix it by not splitting hole extents.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
The usage of 'source' is a bashism, and '.' should be used instead. This
is causing fuzz-tests/001-simple-unmounted to fail in systems where
/bin/sh isn't bash:
[TEST/fuzz] 001-simple-unmounted
./test.sh: 5: ./test.sh: source: not found
./test.sh: 7: ./test.sh: setup_root_helper: not found
./test.sh: 8: ./test.sh: check_prereq: not found
./test.sh: 18: ./test.sh: check_all_images: not found
Since most (all?) tests actually use /bin/bash, change this test to use
bash too.
Signed-off-by: Luis Henriques <henrix@camandro.org>
Signed-off-by: David Sterba <dsterba@suse.com>
* Before this patch
===============================
# ./btrfs fi show foo # "foo" doesn't mean any valid Btrfs
# # no error message
# echo $?
1
===============================
* After this patch
===============================
# ./btrfs fi show foo
ERROR: foo is not a valid Btrfs
#
# echo $?
1
===============================
Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
The extN filesystem type was lost when the separate tests were created
and we've been testing only ext2. The tests pass for ext3 and ext4
though.
Signed-off-by: David Sterba <dsterba@suse.com>
Add a wrapper that sets up environment the same way a test would use it.
Use it for quick prototyping or testing, the commands and output is
logged.
Signed-off-by: David Sterba <dsterba@suse.com>
Split the big function to several helpers so we can use them separately.
Add comments and do minor tweaks.
Signed-off-by: David Sterba <dsterba@suse.com>
stripesize should ideally be set to the value of sectorsize. However
previous versions of btrfs-progs/mkfs.btrfs had set stripesize to a
value of 4096. On machines with PAGE_SIZE other than 4096, This could
lead to the following scenario,
- /dev/loop0, /dev/loop1 and /dev/loop2 are mounted as a single
filesystem. The filesystem was created by an older version of mkfs.btrfs
which set stripesize to 4k.
- losetup -a
/dev/loop0: [0030]:19477 (/root/disk-imgs/file-0.img)
/dev/loop1: [0030]:16577 (/root/disk-imgs/file-1.img)
/dev/loop2: [64770]:3423229 (/root/disk-imgs/file-2.img)
- /etc/mtab lists only /dev/loop0
- losetup /dev/loop4 /root/disk-imgs/file-1.img
The new mkfs.btrfs invoked as 'mkfs.btrfs -f /dev/loop4' succeeds even
though /dev/loop1 has already been mounted and has
/root/disk-imgs/file-1.img as its backing file.
The above behaviour occurs because check_super() function returns an
error code (due to stripesize not being set to 4096) and hence
check_mounted_where() function treats /dev/loop1 as a disk containing a
filesystem other than Btrfs.
Hence as a workaround this commit allows 4096 as a valid stripesize.
Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Commit 6bdf962fe35a8648d(btrfs-progs: Read qgroup status for qgroup
verify) will read qgroup status, and then use it to skip qgroup
reporting.
However since the rescan_running/inconsistent flags are only 1 bit long,
while qgroup flags & BTRFS_QGROUP_FLAGS returns value longer than 1bit,
it doesn't work.
Fix it by doing double negation on (flags & BTRFS_QGROUP_FLAGS) to
convert it to either 1 or 0.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>