Commit Graph

452 Commits

Author SHA1 Message Date
David Sterba b764ba3c4a btrfs-progs: cmds: drop unsigned long long casts for printf
The %llu specifier does not need the typecast for ULL for a long time,
remove it.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-11-03 18:04:37 +01:00
David Sterba eea8dab0fc btrfs-progs: device usage: fix error reporting number of devices 0 != 1
Due to refactoring in 88c25674c7 ("btrfs-progs: convert device info
to struct array") the variable tracking number of devices was not
updated and led to an error.

  $ btrfs device usage /path
  ERROR: unexpected number of devices: 0 != 1
  ...

Issue: #697
Signed-off-by: David Sterba <dsterba@suse.com>
2023-11-03 18:04:37 +01:00
Sidong Yang ac4bb90e7b btrfs-progs: subvolume create: add option -p option to create parent directories
Add new option -p to 'subvolume create' so it behaves like 'mkdir -p'
and create all missing path components before the subvolume.

Issue: #429
Signed-off-by: Sidong Yang <realwakka@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-21 15:51:07 +02:00
Qu Wenruo 660dd1ed71 btrfs-progs: scrub: use device's used_bytes to print summary for running scrubs
[BUG]
For running scrubs, with v6.3 and newer btrfs-progs, it can report
incorrect "Total to scrub":

  Scrub resumed:    Mon Oct  9 11:28:33 2023
  Status:           running
  Duration:         0:44:36
  Time left:        0:00:00
  ETA:              Mon Oct  9 11:51:38 2023
  Total to scrub:   625.49GiB
  Bytes scrubbed:   625.49GiB  (100.00%)
  Rate:             239.35MiB/s
  Error summary:    no errors found

[CAUSE]
Commit c88ac0170b ("btrfs-progs: scrub: unify the output numbers for
"Total to scrub"") changed the output method for "Total to scrub", but
that value is only suitable for finished scrubs.

For running scrubs, if we use the currently scrubbed values, it would
lead to the above problem.

The real scrubbed bytes is only reliable for finished scrubs, not for
running/canceled/interrupted ones.

[FIX]
Change print_scrub_dev() to do extra checks, and only for finished
scrubs to use the scrubbed bytes.
Otherwise fall back to the device's bytes_used.

Issue: #690
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-21 15:51:07 +02:00
David Sterba 88c25674c7 btrfs-progs: convert device info to struct array
The device infos are passed as two parameters, use struct array for that.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-17 19:34:00 +02:00
David Sterba 0fdfcddac4 btrfs-progs: convert chunk info to struct array
Use the struct array for passing around the chunk info instead of the
pointer and size.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-17 19:33:59 +02:00
Sidong Yang 8473ab8131 btrfs-progs: qgroup: check null when comparing paths
This patch fixes a bug that could occur when comparing paths in showing
qgroups list. Old code doesn't check it and the bug occurs when there is
stale qgroup and its path is null. Check whether it is null and return
without comparing paths.

Issue: #687
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Sidong Yang <realwakka@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-13 18:13:12 +02:00
Qu Wenruo 42404a4e44 btrfs-progs: move inode cache removal to rescue group
The option "--clear-ino-cache" is not really that suitable for "btrfs
check" group.

Let's move it to "btrfs rescue" group to fix those small hiccups, just
like the existing "btrfs rescue fix-device-size" command.

For now, "btrfs check --clear-ino-cache" would still work, with one
extra warning referring to "btrfs rescue clear-ino-cache".
This is mostly to reduce the surprise, and keep script users (I doubt if
there is any though) happy for now.

In the next or two releases, we would fully remove the support in "btrfs
check" group.

Another small change is, in the documents, we refer to the feature as
"inode map", which doesn't match with the mount option documents.
Since we're here, unify them to "inode cache" feature.

Issue: #669
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-13 18:13:12 +02:00
Qu Wenruo 930c6362d1 btrfs-progs: fix all variable shadowing
There are quite some variable shadowing in btrfs-progs, most of them are
just reusing some common names like tmp.
And those are quite safe and the shadowed one are even different type.

But there are some exceptions:

- @end in traverse_tree_blocks()
  There is already an @end with the same type, but a different meaning
  (the end of the current extent buffer passed in).
  Just rename it to @child_end.

- @start in generate_new_data_csums_range()
  Just rename it to @csum_start.

- @size of fixup_chunk_tree_block()
  This one is particularly bad, we declare a local @size and initialize
  it to -1, then before we really utilize the variable @size, we
  immediately reset it to 0, then pass it to logical_to_physical().
  Then there is a location to check if @size is -1, which will always be
  true.

  According to the code in logical_to_physical(), @size would be clamped
  down by its original value, thus our local @size will always be 0.

  This patch would rename the local @size to @found_size, and only set
  it to -1.
  The call site is only to pass something as logical_to_physical()
  requires a non-NULL pointer.
  We don't really need to bother the returned value.

- duplicated @ref declaration in run_delayed_tree_ref()
- duplicated @super_flags in change_meta_csums()
  Just delete the duplicated one.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-10 19:16:29 +02:00
Qu Wenruo 5ceec3bcf9 btrfs-progs: dump-tree: allow using '-' for tree ids
Currently for multi-word tree names, we only allow '_' to connect the
two words, like "block_group".

Meanwhile for mkfs features, we go '-' to connect two words, like
"block-group-tree".
This makes users to use different separators for different commands.

This patch would allow using both '-' and '_' for tree ids.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-06 17:33:08 +02: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
Josef Bacik f4e16e0238 btrfs-progs: update read_tree_block to take a btrfs_parent_tree_check
In the kernel we've added a control struct to handle the different
checks we want to do on extent buffers when we read them.  Update our
copy of read_tree_block to take this as an argument, then update all of
the callers to use the new structure.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-03 01:11:57 +02:00
Josef Bacik 2d8058ae09 btrfs-progs: replace blocksize with parent argument for btrfs_alloc_tree_block
In the kernel we pass in the parent to btrfs_alloc_tree_block instead of
the blocksize and simply derive the blocksize from the fs_info.  Update
the function to match the kernel's convention and update all of the
callers so we can sync ctree.c easily.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-03 01:11:56 +02:00
Josef Bacik 8069b8b8cd btrfs-progs: drop btrfs_init_path
This simply zero's out the path, and this is used everywhere we use a
stack path.  Drop this usage and simply init the path's to empty instead
of using a function to do the memset.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-03 01:11:56 +02:00
Josef Bacik 58a96d5230 btrfs-progs: update btrfs_print_leaf to match the kernel definition
In the kernel we have btrfs_print_leaf(eb) instead of
btrfs_print_leaf(eb, mode).  In fact in all of the kernel-shared sources
we're just using the default mode.  Fix this to have a
__btrfs_print_leaf() which handles the mode for the user space utilities
that want the different behavior, and then change btrfs_print_leaf() to
just be the normal default style.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-03 01:11:55 +02:00
Josef Bacik e6c880a2b3 btrfs-progs: update read_node_slot to match the kernel definition
In the kernel this is called btrfs_read_node_slot, and it doesn't take a
btrfs_fs_info.  Update the btrfs-progs version to match the kernel and
update all of the callers.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-03 01:11:55 +02:00
Josef Bacik f94ad0c516 btrfs-progs: pass btrfs_trans_handle through btrfs_clear_buffer_dirty
This is the calling convention in the kernel because we track dirty
blocks per transaction instead of globally in the fs_info.  Simply
mirror what we do in the kernel to make it easier to sync ctree.c
locally.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-03 01:11:55 +02:00
Boris Burkov b3104bfeda btrfs-progs: quota: add support for squota
Add a new option --simple to 'btrfs quota enable'. If set, this enables
simple quotas instead of full qgroups by using the new ioctl command
value.

Signed-off-by: Boris Burkov <boris@bur.io>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-03 01:11:55 +02:00
Qu Wenruo c94965198a btrfs-progs: replace errno with %m in cmd_inspect_list_chunks()
The variable @e is only utilized to record the errno from ioctl() call,
and is only for the error message.

We can go with "%m" to replace the usage of variable @e, and remove the
variable shadowing, as later we will declare a local variable @e with a
different type.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-02 18:41:08 +02:00
David Sterba 553273a834 btrfs-progs: dump-tree: fix block group tree short name
The option -t recognizes tree names in various names and the stem must
not contain the "_TREE", which the bgt had.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-02 18:41:08 +02:00
Johannes Thumshirn 81d6ecd5c2 btrfs-progs: add dump tree support for the raid stripe tree
Add support for the RAID stripe tree to btrfs inspect-internal dump-tree.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-02 18:41:08 +02:00
Anand Jain a11d468e98 btrfs-progs: rename fs_devices::list to match the kernel
Aligning with the kernel's struct btrfs_fs_devices:fs_list, rename
btrfs_fs_devices::list to btrfs_fs_devices::fs_list.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:58 +02:00
Josef Bacik 0ba50a27f4 btrfs-progs: fix improper error handling in btrfs filesystem usage
I was seeing test-cli/016 failures because it claimed we were getting
EPERM from the TREE_SEARCH ioctl to get the chunk info out of the file
system.  This turned out to be because errno was already set going into
this function, the ioctl itself wasn't actually failing.  Fix this by
checking for a return value from the ioctl first, and then returning
-EPERM if appropriate.  This fixed the failures in my setup.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:25 +02:00
David Sterba 5b9206727b btrfs-progs: rename and move get_device_info
The helper belongs to the device-utils, move it there and use the common
prefix.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:24 +02:00
David Sterba 4a96a935ad btrfs-progs: move sysfs related helpers to own file
The sysfs could use more convenience helpers so move the current code to
own file before adding more helpers.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:24 +02:00
David Sterba 00e401752f btrfs-progs: list-chunks: port to sorting API
Use the sorting API. This is 1:1 transformation of previous single key
sorting and needs to be updated so there are multiple accepted instead.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:24 +02:00
Francesco Yoshi Gobbo 240f518441 btrfs-progs: balance start: fix typo in help text
Pull-request: #660
Author: Francesco Yoshi Gobbo <yoshi@fgobbo.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:24 +02:00
David Sterba 7ed79f2b3b btrfs-progs: use escaped format for subvolume path strings in json
Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:23 +02:00
David Sterba 70ae158ec8 btrfs-progs: rename time-long format name to date-time
Make the timestamp format more descriptive what is actually printed. We
may need separate date or time in the future.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:23 +02:00
David Sterba 29060ec176 btrfs-progs: subvolume show: print all items unconditionally in json
The json output could be easily filtered on the user side so we'll print
everything unconditionally.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:23 +02:00
David Sterba 42d0861e31 btrfs-progs: subvolume: rename some json key names
Don't abbreviate generation and use qgroup where it's related to the
qgroup itself and not quotas in general.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:23 +02:00
David Sterba 6120fdadc2 btrfs-progs: subvolume: move json format output under experimental
The format of the json data needs some time to be finalized so it'll
be under experimental.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:23 +02:00
Christoph Heiss 328333f9cf btrfs-progs: subvol show: implement json format output
Implements JSON-formatted output for the `subvolume list` command using
the `--format json` global option, much like it is implemented for other
commands.

Signed-off-by: Christoph Heiss <christoph@c8h4.io>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:23 +02:00
Christoph Heiss f134c86411 btrfs-progs: subvol get-default: implement json format output
Implements JSON-formatted output for the `subvolume get-default` command
using the `--format json` global option, much like it is implemented for
other commands.

Signed-off-by: Christoph Heiss <christoph@c8h4.io>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:23 +02:00
Christoph Heiss ee233db769 btrfs-progs: subvol list: implement json format output
Implements JSON-formatted output for the `subvolume list` command using
the `--format json` global option, much like it is implemented for other
commands.

Re-uses the `btrfs_list_layout` infrastructure to nicely fit it into the
existing formatting code.

A notable difference to the normal, text-based output is that in the
JSON output, timestamps include the timezone offset as well.

Signed-off-by: Christoph Heiss <christoph@c8h4.io>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:23 +02:00
Christoph Heiss da440e66fb btrfs-progs: subvol: introduce rowspec definition for json output
List and export all fields that may be needed for any subvolume related
json output.

Signed-off-by: Christoph Heiss <christoph@c8h4.io>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:23 +02:00
Christoph Heiss 7c983d2352 btrfs-progs: subvol show: factor out text printing to own function
Prepare for switching the plain and json output. The format is slightly
different so we can't utilize the unified fmt_* helpers and two separate
printer functions make more sense.

Signed-off-by: Christoph Heiss <christoph@c8h4.io>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:23 +02:00
Christoph Heiss 8b73f22484 btrfs-progs: subvol show: remove duplicated quotas error check
The exact same check is repeated here, with the second being dead code.
Keep the second instance, as that informs the user what is happening.

Signed-off-by: Christoph Heiss <christoph@c8h4.io>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:23 +02:00
David Sterba 6a3c7aac45 btrfs-progs: list-chunks: rename variables, adjust LNumber starting point
Rename variables tracking ordering, print the logical number starting
from 1 for consistency.

Sample output, sorted by usage:

Number      Type/profile    PStart    Length     PEnd LNumber   LStart Usage%
------ ----------------- --------- --------- -------- ------- -------- ------
     1     System/single   1.00MiB   4.00MiB  5.00MiB       1  1.00MiB   1.56
     2   Metadata/single   5.00MiB   8.00MiB 13.00MiB       2  5.00MiB   2.34
     3       Data/single  12.27GiB   1.00GiB 13.27GiB      17 77.02GiB   2.62
     4       Data/single  11.27GiB   1.00GiB 12.27GiB      15 75.77GiB   3.72
     5       Data/single  13.27GiB   1.00GiB 14.27GiB      18 78.02GiB   3.76
     6   Metadata/single   2.27GiB 256.00MiB  2.52GiB       6 68.02GiB   3.98
     7       Data/single  10.27GiB   1.00GiB 11.27GiB      14 74.77GiB   4.01
     8       Data/single   9.27GiB   1.00GiB 10.27GiB      13 73.77GiB   4.14
     9   Metadata/single   5.77GiB 256.00MiB  6.02GiB      12 73.52GiB   7.89
    10   Metadata/single   6.02GiB 256.00MiB  6.27GiB      16 76.77GiB   9.23
    11       Data/single  16.27GiB   1.00GiB 17.27GiB      19 81.02GiB  18.25
    12       Data/single   8.27GiB   1.00GiB  9.27GiB      11 72.52GiB  39.90
    13       Data/single   3.52GiB   1.00GiB  4.52GiB       8 69.27GiB  44.52
    14       Data/single   6.27GiB   1.00GiB  7.27GiB       3 65.02GiB  57.73
    15       Data/single   4.52GiB   1.00GiB  5.52GiB       9 70.27GiB  59.63
    16       Data/single 277.00MiB   1.00GiB  1.27GiB       4 66.02GiB  60.43
    17       Data/single   2.52GiB   1.00GiB  3.52GiB       7 68.27GiB  61.37
    18       Data/single   1.27GiB   1.00GiB  2.27GiB       5 67.02GiB  62.35
    19       Data/single   7.27GiB   1.00GiB  8.27GiB      10 71.52GiB  64.99

Signed-off-by: David Sterba <dsterba@suse.com>
2023-07-27 14:45:29 +02:00
David Sterba cac019e583 btrfs-progs: list-chunks: update column names
Make the column names more descriptive, PNumber is from times when there
was only physical sort. Make the type/profile more explicit, later it
can be filtered by that. The 'Age' reflects the current allocation
strategy to always pick a higher number but this could become confusing,
it's really the number when sorted by logical offset.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-07-27 14:45:29 +02:00
David Sterba 8d2843afca btrfs-progs: list-chunks: reflow help text of --sort
Now we can use newlines in option descriptions to make nicer lists for
options:

    --sort MODE               sort by a column ascending (default: pstart),
                              MODE can be one of:
                              pstart - physical offset, grouped by device
                              lstart - logical offset
                              usage - by chunk usage (implies --usage)
                              length_p - by chunk length, secondary by physical offset
                              length_l - by chunk length, secondary by logical offset

Signed-off-by: David Sterba <dsterba@suse.com>
2023-07-27 14:45:29 +02:00
David Sterba 3d17609d66 btrfs-progs: list-chunks: add sorting by length
Signed-off-by: David Sterba <dsterba@suse.com>
2023-07-27 14:45:29 +02:00
David Sterba 73c5ad0d70 btrfs-progs: list-chunks: add sorting by usage
Add another sorting key 'usage' to sort chunks by usage, ascending. Also
implies --usage parameter so it's viewed. This ignores devid, so all
chunks are mixed.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-07-27 14:45:29 +02:00
David Sterba c77f2f9f0d btrfs-progs: replace: properly enqueue if there's another replace running
Enqueuing allows to let some operations to wait until the current one
finishes. This usually means that it's waiting for another one, but in
case of replace there's a check that does not allow the enqueuing to
take place, as reported.

Move it before that check.

Issue: #645
Signed-off-by: David Sterba <dsterba@suse.com>
2023-07-26 15:00:48 +02:00
Anand Jain e408cfb49b btrfs-progs: factor out btrfs_scan_argv_devices
To prepare for handling command line given devices factor out
btrfs_scan_argv_devices().

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-07-26 15:00:48 +02:00
Anand Jain dc9e80192b btrfs-progs: drop open_ctree_flags variable in cmd_inspect_dump_tree
Local variable open_ctree_flags carries the flags whose final update is
for the locally declared struct variable oca_flags. Just use oca.flags
directly.

Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-07-26 15:00:48 +02:00
Anand Jain d46a0ef6a0 btrfs-progs: rename struct open_ctree_flags to open_ctree_args
The struct open_ctree_flags currently holds arguments for
open_ctree_fs_info(), it can be confusing when mixed with a local variable
named open_ctree_flags as below in the function cmd_inspect_dump_tree().

  cmd_inspect_dump_tree()
  ::
  struct open_ctree_flags ocf = { 0 };
  ::
  unsigned open_ctree_flags;

So rename struct open_ctree_flags to struct open_ctree_args.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-07-26 15:00:47 +02:00
Anand Jain 82a9870d48 btrfs-progs: dump-super: fix read beyond device size
On aarch64 systems with glibc 2.28, several btrfs-progs test cases are
failing because the command 'btrfs inspect dump-super -a <dev>' reports
an error when it attempts to read beyond the disk/file-image size.

  $ btrfs inspect dump-super -a /dev/vdb12
  <snap>
  ERROR: Failed to read the superblock on /dev/vdb12 at 274877906944

And btrfs/184 also fails, as it uses -s 2 option to dump the last super
block.

	$ ./check btrfs/184
	FSTYP         -- btrfs
	PLATFORM      -- Linux/aarch64 a4k 6.4.0-rc7+ #7 SMP PREEMPT Sat Jun 24 02:47:24 EDT 2023
	MKFS_OPTIONS  -- /dev/vdb2
	MOUNT_OPTIONS -- /dev/vdb2 /mnt/scratch

	btrfs/184 1s ... [failed, exit status 1]- output mismatch (see /Volumes/ws/xfstests-dev/results//btrfs/184.out.bad)
	    --- tests/btrfs/184.out    2020-03-03 00:26:40.172081468 -0500
	    +++ /Volumes/ws/xfstests-dev/results//btrfs/184.out.bad    2023-06-24 05:54:40.868210737 -0400
	    @@ -1,2 +1,3 @@
	     QA output created by 184
	    -Silence is golden
	    +Deleted dev superblocks not scratched
	    +(see /Volumes/ws/xfstests-dev/results//btrfs/184.full for details)
	    ...
	    (Run 'diff -u /Volumes/ws/xfstests-dev/tests/btrfs/184.out /Volumes/ws/xfstests-dev/results//btrfs/184.out.bad'  to see the entire diff)
	Ran: btrfs/184
	Failures: btrfs/184
	Failed 1 of 1 tests

This is because `pread()` behaves differently on aarch64 and sets
`errno = 2` instead of the usual `errno = 0`.

To fix check if the sb offset is beyond the device size or regular file
size and skip the corresponding sbread().

Also, move putchar('\n') after a successful call to load_and_dump_sb() to
the load_and_dump_sb() itself.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-07-26 15:00:47 +02:00
Anand Jain 8da82cde9c btrfs-progs: dump-super: drop the label out and variable ret
In cmd_inspect_dump_super(), at the label 'out', nothing much happens
other than returning ret.

At the goto statement to the label, in the for loop, we perform close(fd).
However, moving the close(fd) to 'out' as well is not a good idea because
close(fd) doesn't make sense outside the for loop.

Instead, simply return 1 instead of ret=1 and then returning it. Drop both
the 'out' label and ret.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-07-26 15:00:41 +02:00
Anand Jain 4ab083175a btrfs-progs: dump-super: improve error message on failed read
Add more error information to help debugging:

  $ ./btrfs inspect-internal dump-super -Ffa /dev/vdb10

  Before:
  ERROR: failed to read the superblock on /dev/vdb10 at 274877906944

  After:
  ERROR: failed to read the superblock on /dev/vdb10 at 274877906944 read 0/4096 bytes

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-07-26 14:59:10 +02:00