Commit graph

19 commits

Author SHA1 Message Date
David Sterba 060f7d6c81 btrfs-progs: handle write errors in btrfs_add_to_fsid()
Add template for read/write error messages and use it for write of
superblock when adding a device. sbwrite() is wrapper around write that
makes sure the zoned devices are accessed correctly.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-16 22:25:50 +01:00
David Sterba 3b560a6649 btrfs-progs: handle range overlaps in extent-tree-utils.c
Add new error message template and use it to report invalid range
overlaps and do proper error handling.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-15 00:16:32 +01:00
David Sterba 21aa6777b2 btrfs-progs: clean up includes, using include-what-you-use
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-03 01:11:57 +02:00
David Sterba 164bc10dfc btrfs-progs: add musl compatibility for printf format %pV
Glibc provides an interface to extend the printf formats but this is not
standardized and does not work on musl. The code brought from kernel
uses %pV for varargs and also has own implementation of printk.

As a workaround for musl expand the pV value to a string and then
simply print it. The details are hidden behind macros:

- DECLARE_PV(vaf)
- PV_ASSIGN(vaf, format, args)
- PV_FMT in printf string
- PV_VAL in arguments

Signed-off-by: David Sterba <dsterba@suse.com>
2023-05-26 18:02:28 +02:00
Josef Bacik 762dbd6d70 btrfs-progs: add struct va_format support to our btrfs_no_printk helper
We use the struct va_format to do nested printk's internally with our
message handling.  Add the appropriate user space code to make this work
properly so when we start copying this code into btrfs-progs we get the
proper messages.

Note: this breaks build on musl, printf.h is not available.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-05-26 18:02:28 +02:00
Josef Bacik 228aa34f10 btrfs-progs: sync messages.[ch] from the kernel
These are the printk helpers from the kernel.  There were a few
modifications, the hi-lights are

- We do not have fs_info::fs_state, so that needed to be removed.
- We do not have discard.h sync'ed yet, so that dependency was dropped.
- Anything related to struct super_block was commented out.
- The transaction abort had to be modified to fit with the current
  btrfs-progs code.
- Added a btrfs_no_printk() helper to common/messages.* so that the
  print statements still worked.
- The 32bit limit checkers are not needed so are behind __KERNEL__

Additionally there were kerncompat.h changes that needed to be made to
handle the dependencies properly.  Those are easier to spot.

Any function that needed to be modified has a MODIFIED tag in the
comment section with a list of things that were changed.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-05-26 18:02:28 +02:00
Josef Bacik 6636d9a6e2 btrfs-progs: consolidate the btrfs message helpers
These helpers all do variations on the same thing, so add a helper to
just do the printf part, and a macro to handle the special prefix and
postfix, and then make the helpers just use the macro and new helper.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-05-26 18:02:28 +02:00
Josef Bacik 49581d0556 btrfs-progs: remove the _on() related message helpers
We have different helpers for warning_on and error_on(), which take the
condition and then do the printf.  However we can just check the
condition in the macro and call the normal warning or error helper, so
clean this usage up and delete the unneeded message helpers.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-05-26 18:02:28 +02:00
Josef Bacik e051593934 btrfs-progs: move BTRFS_DISABLE_BACKTRACE check in print_trace
Everybody who calls print_trace wraps it around this check, move the
check instead to print_trace and remove the check from all the callers.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-05-26 18:02:28 +02:00
David Sterba c780ab6611 btrfs-progs: add helper to print messages to stderr
Add similar helper to pr_verbose that prints on stderr, for commands
that need to print to stderr based on the set verbosity level.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:11 +02:00
David Sterba 964a6377e7 btrfs-progs: factor out check for message level
Factor out the level check so we can add helper for stderr as some
commands don't/can't print to stdout.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:11 +02:00
David Sterba dd724f2180 btrfs-progs: add logic to handle LOG_DEFAULT messages
There are messages that are supposed to be printed by default and now
use the LOG_ALWAYS level, but that's a negative level and was meant as a
workaround for commands that must really print the message.

The default log level should be 1 and can be adjusted by the -q or -v
global commands.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:10 +02:00
David Sterba 8025583af3 btrfs-progs: use common define error and warning message prefixes
Define the message prefix in one place.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:10 +02:00
David Sterba a827bb2db8 btrfs-progs: use template for transaction commit error messages
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:10 +02:00
David Sterba 8fcafae04a btrfs-progs: use template for transaction start error messages
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:10 +02:00
David Sterba 74eb8c68cf btrfs-progs: add template for common error messages
There are several generic errors that repeat the same message. Define a
template for such messages, with optional text.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:09 +02:00
David Sterba d35b7f87c4 btrfs-progs: factor out common message helper for internal errors
In a few occasions there's an internal report, make a common helper so
the prefix message is not necessary and the stack trace can be printed
if enabled.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:09 +02:00
Anand Jain 018448ed62 btrfs-progs: add global verbose and quiet options and helper functions
Add --verbose and --quiet command options to show verbose or no output
from the subcommands.  By introducing global a bconf::verbose memeber to
propagate the same down to the subcommand.

Further the added helper function pr_verbose() helps to logs the verbose
messages, based on the state of the %bconf::verbose. And further HELPINFO_
defines are provided for the usage.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:30:43 +02:00
David Sterba d1efe50d0a btrfs-progs: move messages.[ch] to common/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:03 +02:00
Renamed from messages.c (Browse further)