Commit Graph

2015 Commits (4b4d742b26bb81575f67002ac7f3b7a0efffbd95)
 

Author SHA1 Message Date
David Sterba 4b4d742b26 btrfs-progs: tests: verify btrfstune output during uuid-rewrite
The 'Current fsid:' value does not match the real fsid.

Reported-by: Mike Fleetwood <mike.fleetwood@googlemail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-18 19:49:33 +02:00
Qu Wenruo eb81f8d263 btrfs-progs: map-logical: Rework map-logical logics
[BUG]
The original map-logical has the following problems:
1) Assert if we pass any tree root bytenr.
The problem is easy to trigger, here the number 29622272 is the bytenr of tree root:

 # btrfs-map-logical -l 29622272 /dev/sda6
 mirror 1 logical 29622272 physical 38010880 device /dev/sda6
 mirror 2 logical 29622272 physical 1111752704 device /dev/sda6
 extent_io.c:582: free_extent_buffer: Assertion `eb->refs < 0` failed.
 btrfs-map-logical[0x41c464]
 btrfs-map-logical(free_extent_buffer+0xc0)[0x41cf10]
 btrfs-map-logical(btrfs_release_all_roots+0x59)[0x40e649]
 btrfs-map-logical(close_ctree+0x1aa)[0x40f51a]
 btrfs-map-logical(main+0x387)[0x4077c7]
 /usr/lib/libc.so.6(__libc_start_main+0xf0)[0x7f80a5562790]
 btrfs-map-logical(_start+0x29)[0x4078f9]

The problem is that, btrfs-map-logical always use sectorsize as default
block size to call alloc_extent_buffer.
And when it failes to find the block with the same size, it will free
the extent buffer in a incorrect method(Free and create a new one with
refs == 1).

2) Will return map result for non-exist extent.

 # btrfs-map-logical -l 1 -b 123456 /dev/sda6
 mirror 1 logical 1 physical 1 device /dev/sda6
 mirror 1 logical 4097 physical 4097 device /dev/sda6
 mirror 1 logical 8193 physical 8193 device /dev/sda6
 ...

Normally, before bytenr 12582912, there should be no extent as that's
the mkfs time temp metadata/system chunk.

But map-logical will still map them out.

Not to mention the 1 offset among all results.

[FIX]
This patch will rework the whole map logical by the following methods:
1) Always do things inside a extent
Even under the following case, map logical will only return covered
range in existing extents.

	|<------ range given ------->|
|<-Extent A->|	|<-Extent B->|	|<---Extent C->|
Result:
	|<-->|	|<---------->|	|<-->|

So with this patch, we will search extent tree to ensure all operation
are inside a extent before we do some stupid things.

2) No direct call on alloc_extent_buffer function.

That low-level function shouldn't be called at such high level.
It's only designed for low-level tree operation.

So in this patch we will only use safe high level functions avoid such
problem.

[RESULT]
With this patch, no assert will be triggered and better handle on
non-exist extents.

 # btrfs-map-logical -l 29622272 /dev/sda6
 mirror 1 logical 29622272 physical 38010880 device /dev/sda6
 mirror 2 logical 29622272 physical 1111752704 device /dev/sda6

 # btrfs-map-logical -l 1 -b 123456 /dev/sda6
 No extent found at range [1,123457)

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-17 16:10:18 +02:00
Qu Wenruo 1bbd40a1bb Btrfs-progs: map-logical: introduce write_extent_content function
This function will write extent content info desired file.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-17 16:10:09 +02:00
Qu Wenruo 1e28ed2f84 Btrfs-progs: map-logical: introduce print_mapping_info function
The new function will print the mapping info of given range
[logical, logical+len).

Note, caller must ensure the ranges are completely inside an extent.
Or btrfs_map_block can return -ENOENT.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-17 16:09:45 +02:00
Qu Wenruo 02454f307b btrfs-progs: map-logical: introduce map_one_extent function
Introduce the function to get accurate extent length based on extent
tree search.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-17 16:09:33 +02:00
Qu Wenruo 0074cd315c btrfs-progs: export read_extent_data function
Export it for later btrfs-map-logical cleanup.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-17 16:08:35 +02:00
David Sterba cf4eb9a90e
Btrfs progs v4.1-rc1
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-17 12:44:16 +02:00
David Sterba 36cc0b67f7 btrfs-progs: Makefile: fix typo, dependencies for cmds-* files
The dependency generation skipped all cmds-*.c files due to a typo
in variable name, since day one.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-16 17:15:03 +02:00
David Sterba 8c44cd110c btrfs-progs: send utils: deprecate path_cat and path_cat3
The functios do no allocation error handling, use _out variants instead.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-16 17:15:03 +02:00
David Sterba e6658cd54a btrfs-progs: receive: use static buffer for cur_subvol path
The embedded 'path' is a pointera and we can't make it a path buffer due
to API constraints. Use a separate buffer and sto using the unsafe
path_cat interface.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-16 17:15:03 +02:00
David Sterba 34e2149488 btrfs-progs: send utils: switch callbacks to patch_cat3_out
Also switch full_subvol_path to a static buffer as the interface
semantics change.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-16 17:15:02 +02:00
David Sterba 8da9ecb083 btrfs-progs: receive: use static buffer for write_path
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-16 17:15:02 +02:00
David Sterba 36ac098aae btrfs-progs: receive: use static buffer for root_subvol_path
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-16 17:15:02 +02:00
David Sterba 55e4b14b3e btrfs-progs: unify naming of key types in print-tree
Drop the BTRFS_ prefix and _KEY suffix where applicable.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-16 17:15:02 +02:00
David Sterba 63d1957db0 btrfs-progs: send utils: switch callbacks to new helpers
Use a local buffer for full path(s) and avoid dynamic allocations that
happend to be unchecked.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-16 17:15:01 +02:00
David Sterba b6a77a272b btrfs-progs: and new path_cat helpers to send utils
Add versions of path_cat and path_cat3 that do not allocate the memory.
The unhandled memory allocations are still there.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-15 14:09:11 +02:00
David Sterba d304cf1a2d btrfs-progs: send: use static buffer for output file name
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-15 14:09:10 +02:00
David Sterba a245463281 btrfs-progs: receive: use static buffer for source file
We should copy the optarg anyway.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-15 14:09:10 +02:00
David Sterba 210bd3a693 btrfs-progs: receive: use static buffer for mount point option argument
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-15 14:09:09 +02:00
David Sterba 6bfa3cae05 btrfs-progs: add helper for copying paths
Check the source path length and do the copy.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-12 16:44:48 +02:00
David Sterba 230ab9376c btrfs-progs: receive: use static buffer for cur_subvol
Get rid of the allocation. The logic is changed so that a NULL
cur_subvol::path means that no subvolume/snapshot has been found so far.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-12 16:44:48 +02:00
David Sterba 6a039e5063 btrfs-progs: properly set up ioctl arguments
At some places we do not clear the whole ioctl structure and could
pass garbage to kernel. Zero the ioctl vol_args and use a helper for
copying the path.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-12 16:44:48 +02:00
David Sterba 2e151027d2 btrfs-progs: use PATH_MAX instead of BTRFS_PATH_NAME_MAX
The path bufferes should be PATH_MAX but BTRFS_PATH_NAME_MAX is shorter
due to embedding in 4k aligned structures.

The only reason to use BTRFS_PATH_NAME_MAX is for the respective
structures btrfs_ioctl_vol_args::name.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-12 16:44:47 +02:00
David Sterba c55415e4cb btrfs-progs: send: add option to for the no-data mode
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-12 16:44:47 +02:00
David Sterba 14de97259b btrfs-progs: receive: implement the update_extent callback
The callback for the NO_FILE_DATA send flag is missing and would crash
if such stream is received.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-12 14:39:57 +02:00
Josef Bacik b47fdc73c3 btrfs-progs: make receive work inside of subvolumes
Kind of a big feature of btrfs is being able to have a default subvol.  However
the receive code generates the paths to the subvols from the root of the fs,
even in the case of a default subvol.  So instead figure out if we're inside of
a subvol, either because we have a different default or we've chroot'ed and are
using -m.  Then strip this extra path off of the subvol we find so we can look
up our parent properly.  Thanks

Reported-by: Neil Horman <nhorman@redhat.com>
Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-12 14:39:57 +02:00
David Sterba 6d7999d5b7 btrfs-progs: use less memory for pretty_size_mode buffers
Anand reports that the static buffers used for pertty size strings cause
a stack overflow on SPARC. Zach proposed to change the printf format to
wrap the number and the suffix into a macro. This would require to
change all callsites of pretty_size* and is not very convienient to
write.

This patch replaces the per-call-site static buffers with a limited
number for slots that would be used on each invokation of pretty_size
and wrap around. The number of array slots shall be 10 for now, in
current codebase there are no more than 2 calls to pretty_size in a
single argument list.

Reported-by: Anand Jain <Anand.Jain@oracle.com>
CC: Zach Brown <zab@zabbo.net>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-11 01:10:10 +02:00
David Sterba 4ceffd0927 btrfs-progs: print error within test_num_disk_vs_raid
The error string buffer passed as an argument is of a fixed size, though
we could print up to PATH_MAX + something bytes. Print the error message
directly.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-11 00:51:15 +02:00
David Sterba c848046eb9 btrfs-progs: print error within test_dev_for_mkfs
The error string buffer passed as an argument is of a fixed size, though
we could print up to PATH_MAX + something bytes. Print the error message
directly.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-11 00:46:30 +02:00
David Sterba 4647ab887a btrfs-progs: accept --help as option in the standalone utilities
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-11 00:23:30 +02:00
David Sterba 250a58f34d btrfs-progs: add missing includes to header files
Add includes that let the header files compile or add explicit include
of kerncompat if the uXX types are used.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-10 02:52:21 +02:00
David Sterba 76a9be2e72 btrfs-progs: add helper to wait for subvolume cleaning
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-09 19:36:30 +02:00
David Sterba c9f885ec89 btrfs-progs: subvol: let sync check only current deletions
So far the subvol sync command takes a shortcut and looks if there are
any deleted subvols at all. It does not print the deleted subvolumes as
they get cleaned. Arguably this is what the user would like to see and
has to do

 $ btrfs subvol sync /path $(btrfs subvol list -d /path | "extract the ids")

to see the progress.

Make it look for all currently deleted subvolumes automatically and
print the progress as if the ids were listed manually.

This is a slight change in the semantics of the command. Previously, any
new subvol deletion would prevent subvol sync to return. To simulate the
old behaviour, run 'subvol sync' in a loop until it returns 0.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-09 18:18:19 +02:00
David Sterba ff36fbae4d btrfs-progs: cleanup after errors in open_file_or_dir3
We should zero the dirstream in case we close it ourselves, so the
caller does not do it again. Most current callers do not do that and
exit immediatelly.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-09 15:24:51 +02:00
David Sterba f51b76109f btrfs-progs: receive: fix minor resource leak
Resolves-coverity-id: 1302985
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-09 14:58:43 +02:00
David Sterba add9d7fe4b btrfs-progs: print compact help for btrfs
Running 'btrfs' without arguments will print complete help that spans
a lot of lines and is really helpful. Print only subcommand group
names with short descriptions, similar to what 'git' does.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-09 14:27:54 +02:00
David Sterba 330709ee13 btrfs-progs: add command group info strings
They're printed in the 'btrfs' command group summary.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-09 14:26:33 +02:00
David Sterba 54003d7ee6 btrfs-progs: fix argv0_buf handling
The variable argv0_buf was duplicated and the changes done in utils.c
were not propagated to help.c. So if an unknown commandline token was
found, the error message did not contain the known part:

 $ btrfs scrub test
 : unknown token 'test'

instead of

 $ btrfs scrub test
 btrfs scrub: uknown token 'test'

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-09 13:32:32 +02:00
David Sterba e99303c381 btrfs-progs: remove stray deprecation notice
The 1st level balance subcommand is the right one but it accidentally
inherited the notice about 'filesystem balance' deprecation.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-08 18:37:16 +02:00
David Sterba 60447579c4 btrfs-progs: mkfs: make the summary more compact
Single device example:

btrfs-progs v4.0.1-39
See http://btrfs.wiki.kernel.org for more information.

Label:              (null)
UUID:               a88bfc85-b454-4a32-8de7-276c01f04d58
Node size:          16384
Sector size:        4096
Filesystem size:    2.00GiB
Block group profiles:
  Data:             single            8.00MiB
  Metadata:         single            8.00MiB
  System:           single            4.00MiB
SSD detected:       no
Incompat features:  extref, skinny-metadata
Number of devices:  1
Devices:
   ID        SIZE  PATH
    1     2.00GiB  /dev/sda

Multiple devices:

btrfs-progs v4.0.1-39
See http://btrfs.wiki.kernel.org for more information.

Label:              (null)
UUID:               9db282ef-55f3-4070-a59f-012a654614b2
Node size:          16384
Sector size:        4096
Filesystem size:    8.00GiB
Block group profiles:
  Data:             RAID6           417.50MiB
  Metadata:         RAID6           417.50MiB
  System:           RAID6            20.00MiB
SSD detected:       no
Incompat features:  extref, raid56, skinny-metadata
Number of devices:  4
Devices:
   ID        SIZE  PATH
    1     2.00GiB  /dev/sda
    2     2.00GiB  /dev/sdb
    3     2.00GiB  /dev/sdc
    4     2.00GiB  /dev/sdd

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-08 17:51:59 +02:00
David Sterba b6179c8942 btrfs-progs: mkfs: drop mixed from summary
The mixed-bg incompat feature should be enough.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-08 17:50:47 +02:00
David Sterba d209d6fc97 btrfs-progs: mkfs, drop UUID from device summary
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-08 17:50:47 +02:00
David Sterba e8eb7c001d btrfs-progs: mkfs, move uuid to the end of device summary
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-08 17:50:47 +02:00
Goffredo Baroncelli 3afd86683b btrfs-progs: mkfs: print the summary
This patch prints the summary of the filesystem after the creation.
The main fileds printed are:
- devices list with their uuid, devid, path and size
- raid profile (dup,single,raid0...)
- leafsize/nodesize/sectorsize
- filesystem features (raid56, extref, mixed-bg)
- chunk size and type

If the '-v' switched is passed, the output is more verbose; if the '-q'
switched is passed, only the errors are printed.

Below an example:

BTRFS filesystem summary:
  Label:                btrfs-test
  UUID:                 14ae8a88-98ac-4f22-8441-79f76ec622f7

  Node size:            4096
  Leaf size:            4096
  Sector size:          4096
  Initial chunks:
    Data+Metadata:      9.01GiB
    System:             18.06MiB
  Metadata profile:     RAID5
  Data profile:         RAID5
  Mixed mode:           YES
  SSD detected:         NO
  Incompat features:    mixed-bg, extref, raid56
  Number of devices:    10
    UUID                                  ID    SIZE    PATH
    ------------------------------------  --  --------- -----------
    df1c7f50-1980-4da2-8bc9-7ee6ffb0b554   1   50.00GiB /dev/vdb
    32c808a0-cd7b-4497-a2c0-1d77a9854af9   2   50.00GiB /dev/vdc
    3159782e-d108-40bc-9e15-090ecac160b4   3   50.00GiB /dev/vdd
    db7eaf0c-beb8-4093-a9d0-b9c25c146305   4   50.00GiB /dev/vde
    c367ca04-1f71-49c0-a331-11fc0b87e9fc   5   50.00GiB /dev/vdf
    e9b73c86-4058-4b3a-90ac-18741a276e70   6   50.00GiB /dev/vdg
    c4298b7a-ad41-4690-bf10-bf748b319413   7   50.00GiB /dev/vdh
    1cf048c8-af8a-4225-b09a-5d12e9b217fa   8    2.00GiB /dev/vdi
    7e157869-768a-4725-bad5-82e6bd05fd17   9    2.00GiB /dev/vdj
    2c9431ac-c7f0-45a5-8529-cef8cf6e4033  10    2.00GiB /dev/vdk

  Total devices size:                         356.01GiB

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-08 17:50:47 +02:00
Goffredo Baroncelli 23bc56c0e8 btrfs-progs: mkfs: track sizes of created block groups
Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-08 17:50:46 +02:00
Goffredo Baroncelli f8a0b85e38 btrfs-progs: return the fsid from make_btrfs()
The function make_btrfs() has as argument the fsid of the filesystem.
If this fsid is empty or null make_btrfs() generates a new fsid. However
If the buffer is valid (but the string is empty) the generated fsid is
copied back to the caller.

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-08 17:50:46 +02:00
Goffredo Baroncelli b96345c7ff btrfs-progs: add strdup in btrfs_add_to_fsid() to track the device path
When creating a new btrfs_device, copy the path to track it.  This path
is then used by mkfs.btrfs to list all devices.

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-08 17:50:46 +02:00
David Sterba 1bcedaae79 btrfs-progs: mkfs: do not try to register non-block-devices
A mkfs on a regular file will try to call the DEV_SCAN ioctl that will
take the loop through the kernel and fail:

 ERROR: device scan failed './test.img' - Block device required

If a user without permission to open the control device tries to mkfs a
regular file, an error message is printed:

 failed to open /dev/btrfs-control skipping device registration: Permission denied

So we should not try to pass a non-block-device besides that this makes
the --quiet option more quiet.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-08 17:50:46 +02:00
David Sterba 49ac5f50b5 btrfs-progs: mkfs: move info message out of btrfs_add_to_fsid
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-08 17:50:42 +02:00
David Sterba 42a8983143 btrfs-progs: mkfs: accept mixed case for profile names
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-06 01:03:48 +02:00