Commit graph

327 commits

Author SHA1 Message Date
Filipe Manana dd7c458cb3 btrfs-progs: receive: work around failure of fileattr commands
Currently fileattr commands, introduced in the send stream v2, always
fail, since we have commented the FS_IOC_SETFLAGS ioctl() call and set
'ret' to -EOPNOTSUPP, which is then overwritten to -errno, which may
have a random value since it was not initialized before. This results
in a failure like this:

   ERROR: fileattr: set file attributes on p0/f1 failed: Invalid argument

The error reason may be something else, since errno is undefined at
this point.

Unfortunately we don't have a way yet to apply attributes, since the
attributes value we get from the kernel is what we store in flags field
of the inode item. This means that for example we can not just call
FS_IOC_SETFLAGS with the values we got, since they need to be converted
from BTRFS_INODE_* flags to FS_* flags

Besides that we'll have to reorder how we apply certain attributes like
FS_NOCOW_FL for example, which must happen always on an empty file and
right now we run write commands before attempting to change attributes,
as that's the order the kernel sends the operations.

So for now comment all the code, so that anyone using the v2 stream will
not have a receive failure but will get a behaviour like the v1 stream:
file attributes are ignored. This will have to be fixed later, but right
now people can't use a send stream v2 for the purpose of getting better
performance by avoid decompressing extents at the source and compression
of the data at the destination.

Link: https://lore.kernel.org/linux-btrfs/6cb11fa5-c60d-e65b-0295-301a694e66ad@inbox.ru/
Fixes: 8356c423e6 ("btrfs-progs: receive: implement FILEATTR command")
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-11-24 17:29:12 +01:00
David Sterba 4286eb552e Revert "btrfs-progs: resize: return error value from check_resize_args()"
This reverts commit 55438f3930.

The patch breaks resize cancel.

Reproducer:

    #!/bin/bash

    fallocate -l 7g /var/tmp/7g1 && fallocate -l 7g /var/tmp/7g2

    thing1=$(sudo losetup --show -f /var/tmp/7g1)
    thing2=$(sudo losetup --show -f /var/tmp/7g2)

    echo Make the fs
    mkfs.btrfs -L test539 $thing1
    mkdir test539
    mount -L test539 test539

    echo Get rid of devid:1 by adding a new device and removing the original
    btrfs dev add $thing2 test539
    btrfs dev del $thing1 test539
    echo Creating wiggleroom
    fallocate -l 3g test539/3g1 && fallocate -l 3g test539/3g2
    rm test539/3g1

    echo Start a resize operation and wait 3s to run a cancel
    echo Under 6.0 cancel, under 6.0.1 no cancel and runs out of space
    btrfs fi re 2:-4g test539 &
    sleep 3s && btrfs fi re cancel test539
    wait

    echo Cleanup
    umount test539

    losetup -d $thing1 && losetup -d $thing2

    rm /var/tmp/7g{1,2}
    rmdir test539

Issue: #539
Signed-off-by: David Sterba <dsterba@suse.com>
2022-11-24 17:26:24 +01:00
David Sterba 90548b8295 btrfs-progs: filesystem: new subcommand mkswapfile
Add a command to create a new swapfile. The same can be achieved by
seandalone tools but they're just wrappers around the syscalls. The swap
format is simple enough to be created directly without mkswap command so
the swapfile can be created in one go.

The file must not exist before, this is to avoid problems with file
attributes or any other effects of existing extents. This also means the
command can't be used on block devices.

Default size is 2G, minimum size is 40KiB.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-11-08 11:30:21 +01:00
David Sterba 8bc13b39aa btrfs-progs: subvol: fix help text reference to subvolume
The commonly used reference to subvolume id is the one without a dash.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-26 10:15:40 +02:00
David Sterba c24f14c6a4 btrfs-progs: qgroups: update help texts
Where missing, add the second line with more verbose description, fix
typos or formatting.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-26 10:15:40 +02:00
David Sterba 1414ecbb6f btrfs-progs: replace strerror(errno) with %m in printf formats
We're using the %m format where possible.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-26 09:46:22 +02:00
David Sterba 44efde7fa0 btrfs-progs: unify naming of qgroup subvolid helpers
Kernel function name is btrfs_qgroup_subvolid so rename it in progs. The
libbtrfs can't API be changed without versioning so at least add the new
helper.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-26 09:36:44 +02:00
David Sterba 701ab151c2 btrfs-progs: qgroup: new command to delete stale qgroups
A stale qgroup is level 0 and without a corresponding subvolume. There's
no convenient command for removing them and kernel does not remove them
automatically. Add a command so users don't have to parse and script the
output and/or delete them manually.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-26 09:21:35 +02:00
David Sterba 69b0d7756d btrfs-progs: qgroup show: adjust column widths and names
Use more human readable column description and adjust the width. Use a
single "-" for an empty value as is done elsewhere too.

Sample output:

Qgroupid    Referenced    Exclusive   Path
--------    ----------    ---------   ----
0/5           16.00KiB     16.00KiB   <toplevel>
0/256         16.00KiB     16.00KiB   subv1
0/257         16.00KiB     16.00KiB   <stale>
0/258         16.00KiB     16.00KiB   dir1/subv3
0/259         16.00KiB     16.00KiB   snap1
1/1           16.00KiB     16.00KiB   <0 member qgroups>

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-25 21:44:28 +02:00
David Sterba f486f0f01e btrfs-progs: qgroup show: print pretty names of columns
There are two column name definitions, one for sorting and one for more
human readable format but it was not used for some reason.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-25 21:36:51 +02:00
David Sterba 274a53a4d2 btrfs-progs: qgroup show: adjust printed path format
Convert fputs and printf to message helpers that respect the verbosity
levels.

- print <stale> instead of <missing> for qgroups without a corresponding
  subvolume after it was deleted
- print <toplevel> for toplevel
- for higher level qgroups print the number of member groups, 0 if empty
  and not a special string
- drop the <FS_ROOT>
- print paths relative to toplevel path, like subvolume list does by
  default

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-25 21:34:28 +02:00
David Sterba dac73d6e2c btrfs-progs: qgroup show: print subvolume path by default
Previous patch optionally printed the path but it would be better to
print it by default, so drop the option and verbosity. This is a
separate change as the original change was from an old pull request and
it was ported without significant changes first.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-25 21:12:29 +02:00
Jeff Mahoney 8d1c854094 btrfs-progs: qgroup: add path to show output
The 'btrfs qgroup show' command currently only prints qgroup IDs,
forcing the user to resolve which subvolume each corresponds to.

Adds subvolume path resolution to 'qgroup show' so that when
the -P option is used, the last column contains the pathname of
the root of the subvolume it describes.  In the case of nested
qgroups, it will show the number of member qgroups or the paths
of the members if the -v option is used.

Path can also be used as a sort parameter.

Sample output:

qgroupid         rfer         excl       path
--------         ----         ----       ----
0/5          16.00KiB     16.00KiB   <FS_ROOT>
0/256        16.00KiB     16.00KiB   <FS_ROOT>/subv1
0/257        16.00KiB     16.00KiB   <missing>
0/258        16.00KiB     16.00KiB   <FS_ROOT>/subv3
0/259        16.00KiB     16.00KiB   <FS_ROOT>/snap1

Pull-request: #139
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-25 21:12:24 +02:00
Jeff Mahoney f80a6b40b9 btrfs-progs: quota: add -W option to rescan to wait without starting rescan
Adds a new options -W and --wait-norescan to wait for a rescan without
starting a new operation.  This is useful for things like fstests where
we want do to do a "btrfs quota enable" and not continue until the
subsequent rescan has finished.

In addition to documenting the new option in the man page, clean up the
rescan entry to document the -w option a bit better.

Pull-request: #139
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-25 21:12:24 +02:00
David Sterba f6a212b8e6 btrfs-progs: unify naming of subvolume command definitions
Use full 'subvolume' in all cmd defintions to unify that with other
commands.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-25 20:45:00 +02:00
David Sterba eb439bb833 btrfs-progs: quota rescan: add long options for status and wait
Add more descriptive long options to 'btrfs quota rescan'.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-25 11:54:58 +02:00
David Sterba 447f976472 btrfs-progs: subvol delete: update EPERM error message
The message could be confusing in case there's no send in progress and
the real reason is lack of permissions when deleting a subvolume.
Mention the permissions as first reason. Also update documentation.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-24 15:14:47 +02:00
Sidong Yang 55438f3930 btrfs-progs: resize: return error value from check_resize_args()
check_resize_args() function checks user argument amount but does not
return the correct value in case it's not valid.

Signed-off-by: Sidong Yang <realwakka@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-18 15:57:59 +02:00
Wang Yugui f0c2bb0057 btrfs-progs: send: sync splice buf size with kernel when proto 2
When 'btrfs send --proto 2', the max buffer in kernel is changed from
BTRFS_SEND_BUF_SIZE_V1(SZ_64K) to (SZ_16K + BTRFS_MAX_COMPRESSED).

The performance is improved when we use the same buffer size in
btrfs-progs:

without this patch:  57.96s
with this patch:     48.44s

Bigger buffer size 512K was tested too, but it did not improve protocol
2 over 1 significantly.

Signed-off-by: Wang Yugui <wangyugui@e16-tech.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-18 15:43:38 +02:00
David Sterba b2729396d2 btrfs-progs: cmds: use bool for status variables
Using bool for on/off variables is cleaner, convert all in cmds/ .

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:12 +02:00
David Sterba f0df58635e btrfs-progs: send: use pr_stderr for messages
Replace fprintf(stderr, ...) by the level-aware helper instead of the
explicit verbosity level checks. No change for commands that don't have
the global -q/-v options, otherwise the output can be quieted.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:11 +02:00
David Sterba 449aab05be btrfs-progs: restore: use pr_stderr for messages
Replace fprintf(stderr, ...) by the level-aware helper. No change for
commands that don't have the global -q/-v options, otherwise the output
can be quieted.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:11 +02:00
David Sterba 5751a1780a btrfs-progs: replace: use pr_stderr for messages
Replace fprintf(stderr, ...) by the level-aware helper. No change for
commands that don't have the global -q/-v options, otherwise the output
can be quieted.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:11 +02:00
David Sterba fb6e0c5448 btrfs-progs: filesystem: use pr_verbose and pr_stderr for messages
Replace printing to stderr and stdout by the level-aware helper. No
change for commands that don't have the global -q/-v options, otherwise
the output can be quieted.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:11 +02:00
David Sterba 2c8c7ca6da btrfs-progs: balance: use pr_stderr for messages
Replace fprintf(stderr, ...) by the level-aware helper. No change for
commands that don't have the global -q/-v options, otherwise the output
can be quieted.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:11 +02:00
David Sterba be3193371e btrfs-progs: fi du: print warning when file can't be accessed
The message about inaccessible file is printed on stderr but it may be
missed in the output so use the helper for proper warning.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:11 +02:00
David Sterba b0fcdb9224 btrfs-progs: cmds: remove unnecessary casts for u64
The (unsigned long long) type casts can be dropped, printf understands
%llu and u64 and does not warn. In cases where the type is not u64 keep
the cast.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:11 +02:00
David Sterba f83e5d9c7c btrfs-progs: subvolume: use pr_verbose for messages
Replace printf by the level-aware helper. No change for commands that
don't have the global -q/-v options, otherwise the output can be
quieted.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:11 +02:00
David Sterba 032e68ba34 btrfs-progs: subvol list: use pr_verbose for messages
Replace printf by the level-aware helper. No change for commands that
don't have the global -q/-v options, otherwise the output can be
quieted.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:11 +02:00
David Sterba 2def07ac1d btrfs-progs: scrub: use pr_verbose for messages
Replace printf by the level-aware helper. No change for commands that
don't have the global -q/-v options, otherwise the output can be
quieted.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:11 +02:00
David Sterba 9ef6b38726 btrfs-progs: rescue: use pr_verbose for messages
Replace printf by the level-aware helper. No change for commands that
don't have the global -q/-v options, otherwise the output can be
quieted.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:11 +02:00
David Sterba 2c5c4141ba btrfs-progs: quota: use pr_verbose for messages
Replace printf by the level-aware helper. No change for commands that
don't have the global -q/-v options, otherwise the output can be
quieted.

There's no change in qgroup.c yet as the output relies on return value
of the formatter and pr_verbose does not do that.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:11 +02:00
David Sterba c98f9d0392 btrfs-progs: property: use pr_verbose for messages
Replace printf by the level-aware helper. No change for commands that
don't have the global -q/-v options, otherwise the output can be
quieted.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:11 +02:00
David Sterba a2ab9a56ce btrfs-progs: inspect: use pr_verbose for messages
Replace printf by the level-aware helper. No change for commands that
don't have the global -q/-v options, otherwise the output can be
quieted.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:11 +02:00
David Sterba 285e9786da btrfs-progs: filesystem: use pr_verbose for messages
Replace printf by the level-aware helper. No change for commands that
don't have the global -q/-v options, otherwise the output can be
quieted.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:11 +02:00
David Sterba e9d862bcb4 btrfs-progs: fi usage: use pr_verbose for messages
Replace printf by the level-aware helper. No change for commands that
don't have the global -q/-v options, otherwise the output can be
quieted.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:10 +02:00
David Sterba f7d34a572d btrfs-progs: fi du: use pr_verbose for messages
Replace printf by the level-aware helper. No change for commands that
don't have the global -q/-v options, otherwise the output can be
quieted.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:10 +02:00
David Sterba 917907db29 btrfs-progs: device: use pr_verbose for messages
Replace printf by the level-aware helper. No change for commands that
don't have the global -q/-v options, otherwise the output can be
quieted.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:10 +02:00
David Sterba 303bdb827c btrfs-progs: cmds: use LOG_ levels where hardcoded
To make the levels more understandable, use the LOG_ levels instead of
the hardcoded values. Previously the semantics would assume level 0 as
default and 1 and up for increased verbosity, so the LOG_ levels are
typically larger by one.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:10 +02:00
David Sterba 2f491989e1 btrfs-progs: cmds: use LOG_DEFAULT for messages
Use LOG_DEFAULT message level for all commands where it currently uses
the LOG_ALWAYS level. There are now hardcoded values in many other calls
to pr_verbose and this will be updated in following patches.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:10 +02:00
David Sterba a3588b1ef6 btrfs-progs: use our ASSERT macro everywhere
Switch the remaining use of assert() as it lacks the verbose assert that
we have for ASSERT (but otherwise is equivalent).

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:10 +02:00
David Sterba c2be0e2ce0 btrfs-progs: use template for out of memory error messages
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:09 +02:00
David Sterba 9150cdd7e6 btrfs-progs: rename MUST_LOG to LOG_ALWAYS
Rename MUST_LOG Use a prefix LOG_ so we can add more levels, use it
where it was hardcoded as argument to pr_verbose.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:09 +02:00
David Sterba e6fdeb81a9 btrfs-progs: fi usage: unify naming of device and chunk info variables
Use devinfo and chunkinfo and _ret suffix for return variables.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:08 +02:00
Boris Burkov 980ba4e842 btrfs-progs: receive: add support for fs-verity
Process an enable_verity cmd by running the enable verity ioctl on the
file. Since enabling verity denies write access to the file, it is
important that we don't have any open write file descriptors.

This also revs the send stream format to version 3 with no format
changes besides the new commands and attributes. This version is not
finalized and commands may change, also this needs to be synchronized
with any kernel changes.

Note: the build is conditional on the header linux/fsverity.h

Signed-off-by: Boris Burkov <boris@bur.io>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:08 +02:00
David Sterba 0e38e1c4f2 btrfs-progs: use error helper for messages in non-kernel code
Lots of code still uses fprintf(stderr, "...") that should be the
error() helper. The kernel-shared code is left out of the conversion for
now.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:07 +02:00
David Sterba 40c4ba74ec btrfs-progs: cmds: update include lists
The tool IWYU (include what you use) suggests to remove and add some
includes.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:07:59 +02:00
David Sterba d04a1fa10e btrfs-progs: factor filesystem helpers out of utils.c
Group helpers that retrieve information from the filesystem out of
utils.c.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:13 +02:00
David Sterba 6edd4b2121 btrfs-progs: factor string helpers out of utils.c
Utils is the catch-all file, we can now separate some string utility
functions.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:13 +02:00
David Sterba b121ac4404 btrfs-progs: fix path to internal libbtrfsutil includes
All files include the <btrfsutil.h> which could be confused with the
system-wide installation. Drop the -I path from build and use full path
for any libbtrfsutil headers.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:12 +02:00