Commit Graph

4678 Commits (5f5c497c8b556712c10975070a8d234ab19e64a2)
 

Author SHA1 Message Date
David Sterba 5f5c497c8b btrfs-progs: send: add gcc9 workaround for root item reset
Gcc version 9.1.1 reports:

In file included from /usr/include/string.h:494,
                 from kerncompat.h:25,
                 from ctree.h:26,
                 from send-utils.c:26:
In function ‘memset’,
    inlined from ‘btrfs_read_root_item’ at send-utils.c:165:3,
    inlined from ‘subvol_uuid_search2’ at send-utils.c:494:8:
/usr/include/bits/string_fortified.h:71:10: warning: ‘__builtin_memset’ offset [248, 439] from the object at ‘root_item’ is out of the bounds of referenced subobject ‘generation_v2’ with type ‘long long unsigned int’ at offset 239 [-Warray-bounds]
   71 |   return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

That's correct in case the intent is to overwrite just the generation_v2
member, but we want to zero the rest of the root item structure starting
from the generation_v2. No typecasts can obscure that from gcc so the
starting address is calculated as base pointer + member offset.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 02:06:34 +02:00
David Sterba a62b7854de btrfs-progs: utils: split device scanning functions to own file
All helpers and data structures that are used for device registration.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 02:06:34 +02:00
David Sterba ccbea0977b btrfs-progs: utils: split device handling functions to own file
Helpers that read size, do zeoring, trim or prepare/finalize the device.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 02:06:34 +02:00
David Sterba b98a984f0b btrfs-progs: path-utils: rename test_isdir
Rename so it follows the path_ conventions.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 02:06:33 +02:00
David Sterba fc86737f91 btrfs-progs: path-utils: rename is_existing_blk_or_reg_file
Rename and add path_ prefix.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 02:06:33 +02:00
David Sterba 116e27a87a btrfs-progs: path-utils: rename is_path_exist
Rename so it fits the path_ group.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 02:06:33 +02:00
David Sterba facc0b130e btrfs-progs: path-utils: rename is_mount_point
Add path_ prefix and update callers.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 02:06:33 +02:00
David Sterba 89ad5e9dba btrfs-progs: path-utils: rename is_reg_file
Add path_ prefix and update callers.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 02:06:33 +02:00
David Sterba c3b0e6970b btrfs-progs: path-utils: rename is_block_device
Add the path_ prefix and update all callers.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 02:06:33 +02:00
David Sterba f83e81c61b btrfs-progs: utils: split path related utils to own file
Group helpers that return some status of a given path to own file so we
debloat utils.c a bit.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 02:06:31 +02:00
Graham R. Cobb bb1b07848e btrfs-progs: scrub: Fix scrub cancel/resume not to skip most of the disk
When a scrub completes or is cancelled, statistics are updated for
reporting in a later btrfs scrub status command and for resuming the
scrub. Most statistics (such as bytes scrubbed) are additive so scrub
adds the statistics from the current run to the saved statistics.

However, the last_physical statistic is not additive. The value from the
current run should replace the saved value. The current code incorrectly
adds the last_physical from the current run to the previous saved value.

This bug causes the resume point to be incorrectly recorded, so large
areas of the disk are skipped when the scrub resumes. As an example,
assume a disk had 1000000 bytes and scrub was cancelled and resumed each
time 10% (100000 bytes) had been scrubbed.

Run | Start byte | bytes scrubbed | kernel last_physical | saved last_physical
  1 |          0 |         100000 |               100000 |              100000
  2 |     100000 |         100000 |               200000 |              300000
  3 |     300000 |         100000 |               400000 |              700000
  4 |     700000 |         100000 |               800000 |             1500000
  5 |    1500000 |              0 | immediately completes| completed

In this example, only 40% of the disk is actually scrubbed.

This patch changes the saved/displayed last_physical to track the last
reported value from the kernel.

Signed-off-by: Graham R. Cobb <g.btrfs@cobb.uk.net>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:04 +02:00
Su Yue 82cb226f51 btrfs-progs: misc-tests/029: exit manually after run_mayfail()
Since the commmit 8dd3e5dc2d
("btrfs-progs: tests: fix misc-tests/029 to run on NFS") added the
compatibility of NFS, it called run_mayfail() in the last of the test.

However, run_mayfail() always return the original code. If the test
case is not running on NFS, the last `run_mayfail rmdir "$SUBVOL_MNT"`
will fail with return value 1 then the test fails:
================================================================
====== RUN MAYFAIL rmdir btrfs-progs/tests/misc-tests/029-send-p-different-mountpoints/subvol_mnt
rmdir: failed to remove 'btrfs-progs/tests/misc-tests/029-send-p-different-mountpoints/subvol_mnt': No such file or director
failed (ignored, ret=1): rmdir btrfs-progs/tests/misc-tests/029-send-p-different-mountpoints/subvol_mnt
test failed for case 029-send-p-different-mountpoints
=================================================================

Every instrument in this script handles its error well, so do exit 0
manually in the last.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=202645
Fixes: 8dd3e5dc2d ("btrfs-progs: tests: fix misc-tests/029 to run on NFS")
Signed-off-by: Su Yue <Damenly_Su@gmx.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:04 +02:00
David Sterba 3122085a79 btrfs-progs: output formatter infrastructure
Add structures and API for unified output definition and multiple
formatting backends. Currently there's plain text and json.

The format of each row is defined in struct rowspec, selected using a
key and formatted according to the type. There are extended types for
eg. UUID or pretty size, while direct printf format specifiers work too.

Due to different nature of the outputs, the context structure members
are not always used.

* text output mostly uses indentation and formats the name to a given
  width

* json output tracks nesting depth and keeps stack of previous groups
  (list or array) and how many member have been printed, as the
  separators are allowed only between values and must not preced the
  group closing bracket
  the nesting depth is hardcoded to 16, counting the global group

The API provides functions to print simple values and some helpers to
format more complex structures.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:04 +02:00
David Sterba 54fbdafdc5 btrfs-progs: help: define helper for command with flags
Add macro to define a simple command that also gets some non-default
flags, eg. the output formats.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:04 +02:00
David Sterba 17aee13fcd btrfs-progs: define new output format: json
Add the definition, the format is not implemented in any command.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:04 +02:00
David Sterba eb6a09050f btrfs-progs: help: add helpinfo marker for global options
Global options should be printed right after the command options, but
there could be text following the options. Add a marker that will allow
to order the options before that text.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:04 +02:00
Jeff Mahoney a1a5000984 btrfs-progs: add support for output formats
This adds a global --format option to request extended output formats
from each command.

We currently only support text mode.  Command help reports what
output formats are available for each command.  Global help reports
what valid formats are.

If an invalid format is requested, an error is reported and lists the
valid formats.

Each command sets a bitmask that describes which formats it is capable
of outputting.  If a globally valid format is requested of a command
that doesn't support it, an error is reported and command usage dumped.

Commands don't need to specify that they support text output.  All
commands are required to output text.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
[ use global config instead of passing cmd_context ]
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:04 +02:00
David Sterba add5079974 btrfs-progs: fix helpinfo formats, short and options separation
For options that do not have the long description, the empty string is
required to mark where the options start. Some commands were missing
that.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:04 +02:00
David Sterba c8bea2b84b btrfs-progs: move rbtree-utils.[ch] to common/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:04 +02:00
David Sterba 94fced6353 btrfs-progs: build: drop kernel-lib from -I and update paths
Include the files by full path to avoid any confusion in case of
potentially duplicate names.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:04 +02:00
David Sterba c07960c8be btrfs-progs: move utils.[ch] to common/
Update include paths and remove some duplicates.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:04 +02:00
David Sterba 408cec5086 btrfs-progs: move string-table.[ch] to common/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:03 +02:00
David Sterba 07ca08ffba btrfs-progs: move fsfeatures.[ch] to common/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:03 +02:00
David Sterba aac564aca6 btrfs-progs: move commonh to common/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:03 +02:00
David Sterba f93b471143 btrfs-progs: move help.[ch] to common/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:03 +02:00
David Sterba d0970a05cd btrfs-progs: move task-utils.[ch] to common/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:03 +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
David Sterba f63f29e9e9 btrfs-progs: move internal.h to common/
Create directory for all sources that can be used by anything that's not
rellated to a relevant kernel part, all common functions, helpers,
utilities that do not fit any other specific category.

The traditional location would be probably lib/ with all things that are
statically linked to the main binaries, but we have libbtrfs and
libbtrfsutil so this would be confusing.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:03 +02:00
David Sterba 96f58629c6 btrfs-progs: move cmds-send.c to cmds/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:03 +02:00
David Sterba 4f398726d3 btrfs-progs: move all cmds-fi*.c to cmds/
This is the filesystem command group.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:03 +02:00
David Sterba 3bfc7bcfba btrfs-progs: move all cmds-inspect*.c to cmds/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:03 +02:00
David Sterba d8bdd9e6a7 btrfs-progs: move cmds-subvolume.c to cmds/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:02 +02:00
David Sterba 4707a1c3b3 btrfs-progs: move cmds-scrub.c to cmds/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:02 +02:00
David Sterba fd88267f71 btrfs-progs: move cmds-receive.c to cmds/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:02 +02:00
David Sterba f40f752bf6 btrfs-progs: move cmds-balance.c to cmds/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:02 +02:00
David Sterba 4bee9116bb btrfs-progs: move cmds-restore.c to cmds/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:02 +02:00
David Sterba de6b03ca33 btrfs-progs: move cmds-device.c to cmds/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:02 +02:00
David Sterba 87caad49fa btrfs-progs: move cmds-replace.c to cmds/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:02 +02:00
David Sterba 4356aa5f34 btrfs-progs: move and rename super-recover.c cmds/
The file now gets the prefix of the command group.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:02 +02:00
David Sterba b0445ccf0a btrfs-progs: move and rename chunk-recover.c cmds/
The file now gets the prefix of the command group.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:02 +02:00
David Sterba ea7e4fb3d7 btrfs-progs: move cmds/property.c to cmds/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:02 +02:00
David Sterba 605b8c1295 btrfs-progs: move cmds-rescue.c to cmds/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:02 +02:00
David Sterba fc160f4657 btrfs-progs: move cmds-qgroup.c to cmds/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:02 +02:00
David Sterba 64e10d3b6f btrfs-progs: move cmds-quota.c to cmds/
This is first instance of commands files moving to a separate directory,
that will be cmds/, thus the files can drop the prefix. We can further
split files into specific parts of a given command. The quota file was
selected as the smallest.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:02 +02:00
David Sterba 33394a9e9d btrfs-progs: build: support per-file CFLAGS located in directories
Our build allows easy definition of CFLAGs that apply only to a given
file, like cmds_restore_cflags and cmds-restore.c .

This is done by series of transformations that convert the file name to
a variable name, when that is defined it's used.

To support files in directories outside of the top level we need to
convert the / too. The function 'subst' supports only a single string,
so they have to be nested.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:01 +02:00
Nikolay Borisov 32f75c87a0 btrfs-progs: check: Remove duplicated and commented functions
Commit 756105181e ("btrfs-progs: check: supplement extent backref
list with rbtree") changed the backref implementation to use rb tree
and also commented the old implementations. It's been almost 2 years
since that change and it's unlikely the old version will ever be used,
so just remove it.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 13:31:16 +02:00
Nikolay Borisov 16b30ddb28 btrfs-progs: Remove old send buffer copy implementation
Commit ba23855cdc ("btrfs-progs: send: use splice syscall instead of
read/write to transfer buffer") changed the send implementation to use
splice(). The old read/write implementation hasn't be used for at least
3 years, it's time to remove it.

The splice mechanism proved to be reliable and the manual buffer copy
fallback is not needed, besides that splice is probably faster.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 13:31:16 +02:00
Nikolay Borisov 4e34bdb868 btrfs-progs: Remove old commented code
This piece of code has been commented since 2009, given the number of
changes that have happened it's unlikely it could be made to work or is
needed at all. Just delete it.

The code was disabled in commit 95d3f20b51 ("Mixed back reference
(FORWARD ROLLING FORMAT CHANGE)") that changed the format significantly
and we don't need the compatibility code anymore.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 13:31:16 +02:00
Nikolay Borisov 56c31f13d6 btrfs-progs: Remove redundant if
'pin' is always true in __free_extent so there is no point in checking
it. Just remove the if and unindent the code.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 13:31:16 +02:00
David Sterba 0323a6c777 btrfs-progs: scrub: improve output of status
Prievous patch added throughput and time left calculatios, but with more
information it becomes less clear. Switch to the output format used in
several other commands that prints header, followed by colon, whitespace
and the value. Grouped values are indented by 2 spaces.

This patch uses the space info that is more accurate than the total
size. The used space is what scrub will check, however the multiplicity
is not yet taken into account, so this works only for the 'single'
profile.

Sample output:

  UUID:             bf8720e0-606b-4065-8320-b48df2e8e669
  Scrub started:    Fri Jun 14 12:00:00 2019
  Status:           running
  Duration:         0:14:11
  Time left:        0:04:04
  ETA:              Fri Jun 14 12:18:15 2019
  Total to scrub:   182.55GiB
  Bytes scrubbed:   141.80GiB
  Rate:             170.63MiB/s
  Error summary:    csum=7
    Corrected:      0
    Uncorrectable:  7
    Unverified:     0

For the reference, this is 'fi df':

  Data, single: total=261.00GiB, used=179.91GiB
  System, single: total=32.00MiB, used=48.00KiB
  Metadata, single: total=5.00GiB, used=2.64GiB
  GlobalReserve, single: total=375.23MiB, used=0.00B

Several repeated runs of scrub showed that the time estimate is very
close to the final time (within tens of seconds).

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 13:31:16 +02:00