Commit Graph

5098 Commits

Author SHA1 Message Date
Qu Wenruo
ac75513621 btrfs-progs: convert: fix the pointer sign warning for ext2 label
[WARNING]
When compiling btrfs-progs, there is one warning from convert ext2 code:
  convert/source-ext2.c: In function 'ext2_open_fs':
  convert/source-ext2.c:91:44: warning: pointer targets in passing argument 1 of 'strndup' differ in signedness [-Wpointer-sign]
     91 |  cctx->volume_name = strndup(ext2_fs->super->s_volume_name, 16);
        |                              ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
        |                                            |
        |                                            __u8 * {aka unsigned char *}
  In file included from ./kerncompat.h:25,
                   from convert/source-ext2.c:19:
  /usr/include/string.h:175:35: note: expected 'const char *' but argument is of type '__u8 *' {aka 'unsigned char *'}
    175 | extern char *strndup (const char *__string, size_t __n)
        |                       ~~~~~~~~~~~~^~~~~~~~

The toolchain involved is:
- GCC 10.1.0
- e2fsprogs 1.45.6

[CAUSE]
Obviously, in the offending e2fsprogs, the volume label is using u8,
which is unsigned char, not char.

  /*078*/	__u8	s_volume_name[EXT2_LABEL_LEN];	/* volume name, no NUL? */

[FIX]
Just do a forced conversion to suppress the warning is enough.
I don't think we need to apply -Wnopointer-sign yet.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-29 17:45:39 +02:00
Johannes Thumshirn
fba57b689a btrfs-progs: remove btrfs_raid_profile_table
For SINGLE and DUP RAID profiles we can get the num_stripes values from
btrfs_raid_attr::dev:stripes. For all other RAID profiles the value is
calculated anyways.

As this was the last remaining member of the btrfs_raid_profile_table we
can remove it as well.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-29 17:45:39 +02:00
Johannes Thumshirn
1b12bf7b1b btrfs-progs: remove unused btrfs_raid_profile::max_stripes
The max_stripes value of btrfs_raid_profile_table is unused, so we can
just remove it as well.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-29 17:45:39 +02:00
Johannes Thumshirn
563d8a1b4f btrfs-progs: use minimal number of stripes from btrfs_raid_attr
Both btrfs_raid_attr and btrfs_raid_profile define the minimal number of
stripes for each raid profile.

The difference is in btrfs_raid_attr the number of stripes is called
devs_min and in btrfs_raid_profile its called min_stripes.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-29 17:45:39 +02:00
Johannes Thumshirn
6b2d7c799c btrfs-progs: use sub_stripes property from btrfs_raid_attr
Both btrfs_raid_attr and btrfs_raid_profile define the number of
sub_stripes a raid type has.

Use the one from btrfs_raid_attr and get rid of the field in
btrfs_raid_profile.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-29 17:45:39 +02:00
Qu Wenruo
5de63ab1c9 btrfs-progs: mkfs-tests: Add test case to verify the --rootdir size limit
Add a test case to ensure we can create a 350M fs with 128M rootdir.

Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-29 17:45:39 +02:00
Qu Wenruo
0ae7840775 btrfs-progs: fix wrong chunk profile for do_chunk_alloc()
[BUG]
There is a bug report that using DUP data profile, with a 400MiB source
dir, on a 7G disk leads to mkfs failure caused by ENOSPC.

[CAUSE]
After some debugging, it turns out that do_chunk_alloc() is always
passing SINGLE profile for new chunks.

The offending code looks like: extent-tree.c:: do_chunk_alloc()

	ret = btrfs_alloc_chunk(trans, fs_info, &start, &num_bytes,
	                        space_info->flags);

However since commit bce7dbba28 ("Btrfs-progs: only build space info's
for the main flags"), we no longer store the profile bits in space_info
anymore.

This makes space_info never get updated properly, and causing us to
creating more and more chunks to eat up most of the disk with unused
SINGLE chunks, and finally leads to ENOSPC.

[FIX]
Fix the bug by passing the proper flags to btrfs_alloc_chunk().
Also, to address the original problem commit 2689259501 ("btrfs progs:
fix extra metadata chunk allocation in --mixed case") tries to fix, here
we do extra bit OR to ensure we get the proper flags.

Issue: #258
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-29 17:45:35 +02:00
David Sterba
94dbcc2958 btrfs-progs: docs: update bootloader section
Add reference to u-boot and primary super block offset.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-18 11:41:57 +02:00
David Sterba
f1a1184f2c btrfs-progs: fi defrag: clarify recursive mode
Directory symlinks are not followed in the recursive mode, add that to
the documentation.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-17 22:11:12 +02:00
David Sterba
9532249690 btrfs-progs: docs: clarify balance regarding extent sharing
Based on user questions, the word 'rewrite' may sound confusing as the
defragmetation also rewrites data but break extent sharing, while
balance does not do that.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-17 21:19:21 +02:00
Anand Jain
c4cb0e8fc3 btrfs-progs: scrub cancel: add global quiet option
Enable the quiet option to the scrub cancel command.
Does the job quietly. For example:

  $ btrfs -q scrub cancel <mnt>

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:33:25 +02:00
Anand Jain
bdca4824b4 btrfs-progs: scrub start, resume: add global quiet option
Propagate global --quiet option down to the btrfs scrub start and resume
subcommands.

Now both quiet options work:

	$ btrfs -q scrub start <path>
	$ btrfs scrub start -q <path>

	$ btrfs -q scrub resume <path>
	$ btrfs scrub resume -q <path>

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:33:13 +02:00
Anand Jain
4eb7b36534 btrfs-progs: subvolume snapshot: add global quiet option
Enable the quiet option to the subvolume snapshot command.
Does the job quietly. For example:

  $ btrfs -q subvolume snapshot <src> <dest>

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:33:07 +02:00
Anand Jain
a70a1dbf98 btrfs-progs: balance resume: add global quiet option
Enable the quiet option to the balance resume command.
Does the job quietly. For example:

  $ btrfs -q balance resume <path>

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:33:01 +02:00
Anand Jain
9326e1b99a btrfs-progs: balance start: add global quiet option
Enable the quiet option to the balance start command.
Does the job quietly. For example:

  $ btrfs -q balance start --full-balance <path>

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:54 +02:00
Anand Jain
ec2e60bf55 btrfs-progs: subvolume delete: add global quiet option
Enable the quiet option to the subvolume delete command.
Does the job quietly. For example:

  $ btrfs --quiet subvolume delete <path>

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:47 +02:00
Anand Jain
ebeaf0089d btrfs-progs: subvolume create: add global quiet option
Enable the quiet option to the subvolume create command.
Does the job quietly. For example:

  $ btrfs --quiet subvolume create <path>

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:39 +02:00
Anand Jain
c19cc45e5e btrfs-progs: quota rescan: add global quiet option
Enable the quiet option to the quota rescan command.
Does the job quietly. For example:

  $ btrfs --quiet quota rescan

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:29 +02:00
David Sterba
79bb50787a btrfs-progs: add separate verbosity level for on-by-default messages
For backward compatibility with tools that may rely on the messages we
need a special level to print the message unless the verbosity settings
haven't been set on command line.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:29 +02:00
Johannes Thumshirn
5a1a02d208 btrfs-progs: consolidate num_stripes setting for striping RAID levels
All striping RAID Levels use the same method to set the number of RAID
stripes, so consolidate it.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:29 +02:00
Johannes Thumshirn
b9444efb66 btrfs-progs: don't pretend RAID56 has a different stripe length
Since it's addition in 2009 BTRFS RAID5/6 uses a constant stripe length
and we're lacking the meta-data to define a per stripe length, so it's
unlikely to change in the near future for RAID5/6.

So let's not pretend something we don't do and remove the RAID5/6 stripe
length special casing.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:29 +02:00
Johannes Thumshirn
2ef15943a0 btrfs-progs: introduce init_alloc_chunk_ctl
Factor out setting of alloc_chuk_ctl fileds in a separate function
init_alloc_chunk_ctl.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:29 +02:00
Johannes Thumshirn
ed9964895f btrfs-progs: compactify num_stripe setting in btrfs_alloc_chunk
Now that most of the RAID profile dependent chunk allocation parameters
have been converted to table lookus and moved out of the if-statement
maze, all that remains is the actual calculation of the number of stripes.

Compact the 5 if statements into a single switch statemnt to make the code
a bit more compact and more intuitive to follow.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:29 +02:00
Johannes Thumshirn
408264be2c btrfs-progs: consolidate num_stripes sanity check
For all RAID profiles in btrfs_alloc_chunk() we're doing a sanity check if
the number of stripes is smaller than the minimal number of stripes
needed for this profile.

Consolidate this per-profile check to a single check after assigning the
number of stripes to further reduce code.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:29 +02:00
Johannes Thumshirn
268e4382c3 btrfs-progs: do table lookup for simple RAID profiles' num_stripes
For the two simple "RAID" profiles single and dup, we can simply fallback
to a table lookup to get num_stripes.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:29 +02:00
Johannes Thumshirn
63975f0693 btrfs-progs: consolidate setting of RAID1 stripes
All 3 different RAID1 profiles use the same calculation mehod for the
number of used stripes.

Now that we do table lookups fo rmost of the allocation control
parameters, we can consolidate all 3 RAID1 profiles into a single branch
for the calculation.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:29 +02:00
Johannes Thumshirn
9b591da1f6 btrfs-progs: consolidate assignment of sub_stripes
Now that we have a table holding the sub_stripes value we can consolidate
all setting of alloc_chunk_ctl::sub_stripes to a signle table lookup.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:29 +02:00
Johannes Thumshirn
ea110419ff btrfs-progs: consolidate assignment of minimal stripe number
Now that we have a table holding the min_stripes value we can consolidate
all setting of alloc_chunk_ctl::min_stripes to a signle table lookup.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:29 +02:00
Johannes Thumshirn
66a4f47c90 btrfs-progs: introduce raid profile table for chunk allocation
Introduce a table holding the paramenters for chunk allocation per RAID
profile.

Also convert all assignments of hardcoded numbers to table lookups in this
process. Further changes will reduce code duplication even more.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:29 +02:00
Johannes Thumshirn
93f38f0446 btrfs-progs: pass alloc_chunk_ctl to chunk_bytes_by_type
Pass the whole alloc_chunk_ctl to chunk_bytes_by_type instead of its
num_stripes and sub_stripes members.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:29 +02:00
Johannes Thumshirn
53bcec4e39 btrfs-progs: cache number of devices for chunk allocation
Cache the total number of devices usable for chunk allocation in
alloc_chunk_ctl instread of reading it from the super-block over and over
again.

As it's a) unlikely to have more than 4 billion devices and the result of
the max_t() gets truncated to int anyways, change the max_t calls to
simple max(), while we're at it.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:29 +02:00
Johannes Thumshirn
ab470de0fa btrfs-progs: introduce alloc_chunk_ctl structure
Introduce an alloc_chunk_ctl structure, which holds parameters to control
chunk allocation.

Furthermore use this throughout btrfs_alloc_chunk().

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:29 +02:00
Johannes Thumshirn
4e773f9324 btrfs-progs: simplify assignment of number of RAID stripes
Simplify the assignment of the used number of RAID stripes in chunk
allocation.

For RAID levels 0, 5, 6 and 10 we first assigned it to the number of
devices in the file-system and afterwards capped it to the upper bound of
max_stripes. We can just use the max() macro for this.

This will help in furhter refactorings.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:28 +02:00
Johannes Thumshirn
8d51001425 btrfs-progs: simplify minimal stripe number checking
In btrfs_alloc_chunk_ctrl() we have a recurring pattern, first we assign
num stripes, then we test if num_stripes is smaller than a hardcoded
boundary and after that we set min_stripes to this magic value.

Reverse the logic by first assigning min_stripes and then testing
num_stripes against min_stripes.

This will help further refactoring.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:28 +02:00
Anand Jain
9d16aa5a8b btrfs-progs: device scan: add global quiet option
Enable the quiet option to the device scan command.  Does the job
quietly. For example:

  $ btrfs -q device scan

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:19 +02:00
Anand Jain
e7f1d41f3f btrfs-progs: device scan: add global verbose option
Enable verbose output for the device scan, this uses the global verbose
option.

For example:
  $ btrfs -v device scan
  Scanning for Btrfs filesystems
  registered: /dev/sda1
  registered: /dev/sda2
  registered: /dev/sda3
  registered: /dev/sda5
  registered: /dev/sda6

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:08 +02:00
Anand Jain
aeb2242b70 btrfs-progs: refactor btrfs_scan_devices() to accept verbose argument
Function btrfs_scan_devices() is being used by commands such as
'btrfs filesystem' and 'btrfs device', by having the verbose argument in
the btrfs_scan_devices() we can control which threads to print the
messages when verbose is enabled by the global option.

Add an option %verbose to btrfs_scan_devices().

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:31:58 +02:00
Anand Jain
6d022e7af2 btrfs-progs: inspect logical-resolve: add global verbose option
Propagate global --verbose option down to the btrfs inspect-internal
logical-resolve subcommand.

Command 'btrfs inspect-internal logical-resolve' provides local verbose
option this patch makes it enable-able by using the global --verbose
option.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:31:55 +02:00
Anand Jain
32544f4b7e btrfs-progs: inspect inode-resolve: add global verbose
Propagate global --verbose option down to the btrfs inspect-internal
inode-resolve subcommand.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:31:47 +02:00
Anand Jain
502d287265 btrfs-progs: restore: add global verbose option
Propagate global --verbose option down to the btrfs restore subcommand.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:31:41 +02:00
Anand Jain
7c3b845f9d btrfs-progs: super-recover: add global verbose option
Propagate global --verbose option down to the btrfs rescue super-recover
subcommand.

Both global and local verbose options are now supported:

  btrfs -v rescue super-recover
  btrfs rescue super-recover -v

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:31:37 +02:00
Anand Jain
968721ad77 btrfs-progs: chunk-recover: add global verbose option
Propagate global --verbose option down to the btrfs rescue chunk-recover
subcommand.

Both global and local verbose options are now supported and aliases:

 btrfs -v rescue chunk-recover
 btrfs rescue chunk-recover -v

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:31:33 +02:00
Anand Jain
25c8817d87 btrfs-progs: balance status: add global verbose option
Propagate global --verbose option down to the btrfs balance status
subcommand.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:31:30 +02:00
Anand Jain
2540a6d12d btrfs-progs: balance start: add global verbose option
Propagate global --verbose option down to the btrfs balance start
subcommand.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:31:26 +02:00
Anand Jain
db2f85c875 btrfs-progs: fi defrag: add global verbose option
Propagate global --verbose option down to the btrfs receive subcommand.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:31:19 +02:00
Anand Jain
177d307229 btrfs-progs: subvolume delete: add global verbose option
Propagate global --verbose option down to the btrfs subvolume delete
subcommand.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:31:13 +02:00
Anand Jain
1830d002d7 btrfs-progs: receive: add global verbose and quiet options
Propagate global --verbose and --quiet options down to the btrfs receive
subcommand.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:31:07 +02:00
Anand Jain
7881cb21fd btrfs-progs: send: add global verbose and quiet options
Propagate global --verbose and --quiet options down to the btrfs send
subcommand.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:30:59 +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
Anand Jain
b5a6cff94d btrfs-progs: split global help HELPINFO_INSERT_GLOBALS
As of now the define HELPINFO_INSERT_GLOBALS if used as in the example
as below (as of now its not been used anywhere) will print the help
texts as shown below

$ ./btrfs fi show --help

 <snip>

    Global options:
    --format TYPE      where TYPE is: text

So in preparation to add --verbose and --quiet global options, and
apparently --format is not being used yet, this patch splits the global
options into two defines.

                                       "Global options:"

So that the currently added global options --verbose and --quiet can use
the define HELPINFO_INSERT_GLOBALS header as shown below.

$ ./btrfs fi show --help
<snip>

    Global options:

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:30:36 +02:00