Commit Graph

790 Commits (e5c6852c0c4ce72205dd0bab40924d2ace75cb6f)
 

Author SHA1 Message Date
Mark Fasheh e5c6852c0c btrfs-progs: re-add send-test
send-test.c links against libbtrfs and uses the send functionality provided
to decode and print a send stream to the console.

66819df "btrfs-progs: add send-test" contained this file when
submitted, but somehow got lost on commit.

[sandeen@redhat.com: Resurrect lost send-test.c from original commit]

Signed-off-by: Mark Fasheh <mfasheh@suse.de>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-04-23 18:56:20 +02:00
Anand Jain 555ae67390 btrfs-progs: btrfs-select-super output is confusing when it fails
Trivial patch:
./btrfs-progs/btrfs-select-super -s 0 /dev/sdc
using SB copy 0, bytenr 65536
No valid Btrfs found on /dev/sdc
Open ctree failed

The line 'using..' is confusing which gives an
indication that command is successful

This patch will avoid that when command fails

Signed-off-by: Anand Jain <anand.jain@oracle.com>
2013-04-23 18:56:20 +02:00
Anand Jain 4b3c9136be btrfs-progs: mkfs should first check all disks before writing to a disk
In the cases where one of the disk is not suitable for
btrfs, then we would fail the mkfs, however we determine
that after we have written btrfs to the preceding disks.
At this time if user changes mind for not to use btrfs
will left with no choice.

So this patch will check if all the provided disks are
suitable for the btrfs at once before proceeding to
create btrfs on a disk.

Further this patch also removed duplicate code to check
device suitability for the btrfs.

Next, there is an existing bug about the -r mkfs option,
which this patch would carry forward most of it.
Ref:
[PATCH 2/2, RFC] btrfs-progs: overhaul mkfs.btrfs -r option

Signed-off-by: Anand Jain <anand.jain@oracle.com>

to merg prev

Signed-off-by: Anand Jain <anand.jain@oracle.com>
2013-04-23 18:56:20 +02:00
Anand Jain 9b5a329c6c btrfs-progs: no pending balance is not an error
Having no balance running/ paused/completed is a normal
situation, so the current output message should be positive
with return val zero.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
2013-04-23 18:56:20 +02:00
Anand Jain 1c41ab9c4a btrfs-progs: fix btrfs scrub start help
a very trivial fix

Signed-off-by: Anand Jain <anand.jain@oracle.com>
2013-04-23 18:56:19 +02:00
Anand Jain 486e7ca4cd btrfs-progs: delete unused function get_mountpt
and get_btrfs_mount has replaced it

Signed-off-by: Anand Jain <anand.jain@oracle.com>
2013-04-23 18:56:19 +02:00
Stefan Behrens f592cd1cc0 Btrfs-progs: Use /proc/mounts instead of /etc/mtab
/etc/mtab is not working correctly in situations where multiple
mount namespaces are used. Use /proc/mounts instead like the
rest of the code is doing it.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
2013-04-09 18:43:32 +02:00
Jan Schmidt 08fecd7658 Btrfs-progs: add btrfs-crc tool
This tool can be used to compute btrfs' style crc32c checksums for filenames
as done by the kernel. Additionally, there is -c mode to do a brute force
search for file names with a given checksum.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
2013-04-09 18:43:32 +02:00
Zhi Yong Wu b0029a96f2 btrfs-progs: add missing qgroup synopsis in btrfs
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
2013-04-09 18:43:32 +02:00
Zhi Yong Wu 4a14a75789 btrfs-progs: fix one bracket issue in mkfs.btrfs manpage
In "[ \fB\-f\fP\fI ]", the "\fI" will result in the front half "["of
"[ -f ]" doesn't the back half "]"; When you issue the command
"man mkfs.btrfs", you will see the difference.

Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
2013-04-09 18:43:32 +02:00
Josef Bacik d6f7e3da0d Btrfs-progs: make btrfs-image restore with a valid chunk tree V2
Previously btrfs-image would set a METADUMP flag and would make one big system
chunk to cover the entire file system in the super in order to get around the
unpleasant business of having to adjust the chunk tree.  This meant that you
could use the progs stuff on a restored file system, which is great for testing
btrfsck and other such things.  But we want to be able to run the tree log
replay on a file system that is not able to run the tree log replay.  So in
order to do this we need to fixup the super's chunk array and the chunk tree
itself.  This is pretty easy since we restore using the logical offsets of the
metadata, so we just have to set the chunk items to have 1 stripe and have the
stripes point at the primary device and then use the logical offset of the chunk
as the physical offset.  With this patch I can restore a file system image that
had a tree log and mount the file system and have the log be replayed
successfully.  This patch also gives you the -o option in case you want the old
restore way, in the case where we want to make sure the system chunks as they
were given to us are correct.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
2013-04-09 18:43:24 +02:00
Josef Bacik 2881054956 Btrfs-progs: make btrfs-image grab the free space cache
A lot of tree log replay bugs are because of strange space cache setups, so make
btrfs-image scrape the free space cache as well so we can better replicate what
a user is seeing if they have a tree log bug or anything related to free space
cache.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
2013-03-21 19:36:33 +01:00
Josef Bacik 274518d7b8 Btrfs-progs: make btrfs-image copy the tree logs if they exist
Currently btrfs-image doesn't copy the tree logs, which doesn't help me when
we're trying to debug log replay bugs.  Since we don't have entries in the
extent root for the blocks we have to walk down all of the trees in order to
copy them.  With this patch I can image a file system with a tree log and it
works fine.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
2013-03-21 19:36:30 +01:00
Josef Bacik 1bf2717b2f Btrfs-progs: cleanup error handling in btrfs-image
We use BUG_ON() everywhere in btrfs-image.  When users are going to use this
command things are pretty dire, so I'd rather have really good error messages so
I know what happened rather than figure out which one of the 20 BUG_ON()'s made
the stupid thing exit early.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
2013-03-21 19:21:10 +01:00
Arne Jansen 6d37fbfc1f Btrfs-progs: tool to visualize fragmentation
This tool draws per-chunk pngs representing the allocation map. A black
or colored dot means the block is allocated.
The output is written to a subdirectory, together with an index.html to be
viewed in a browser.
There are options to control whether color should be used and which block
group types should be printed.
To build, you need to have libpng and libgd installed. It is not part of
the 'all' target, so please build it explicitely with make btrfs-fragments.

A (rather untypical) example can be seen at

http://sensille.com/fragments

Please regard this as a first scratch version and feel free to improve it :)

Signed-off-by: Arne Jansen <sensille@gmx.net>
2013-03-19 18:24:51 +01:00
Stefan Behrens 4739e7332c Btrfs-progs: make scrub IO priority configurable
The btrfs tool is changed in order to support command line parameters
to configure the IO priority of the scrub tasks. Also the default is
changed. The default IO priority for scrub is the idle class now.

The behavior is the same as when one would type
'ionice ... btrfs scrub start ...' or 'ionice ... btrfs scrub resume ...'
(without this patch applied).
The only reason for adding this to the btrfs tool is that it was not
documented and not obvious that it worked like this, that all internal
scrub tasks inherited the IO priority values of the btrfs tool that is
starting or resuming the scrub operation.

Note that after applying the patch it is no longer possible to set
the IO priority using ionice since the btrfs tool always configures
the priority in order to run in the idle class by default.

Some basic performance measurements have been done with the goal to
measure which IO priority for scrub gives the best overall disk data
throughput. The kernel was configured to use the CFQ IO scheduler
with default configuration and without support for throttling. The
summary is, that the more the disk head movements are avoided, the
faster the overall disk transfer capacity is, which is not really a
big surprise. Therefore it makes sense that the best data throughput
was measured setting the scrub IO priority and the scrub readahead
IO priority to the idle class priority. Running with idle class IO
priority means that scrub and scrub readahead IO is paused while
other tasks access the disk. Doing the tasks one after the other
instead of concurrently avoids many disk head movements. The
overall data throughput of rotating disks is improved this way.

However, if it is desired to have the scrub task done within a
reasonable time, and if at the same time the filesystem is heavily
loaded, the idle IO priority should be avoided. Otherwise the scrub
operation will never take place and thus never terminate.

The best effort IO priority class with the subclass 7 (the lowest
one in the best effort class) is recommended in the case of always
heavily loaded hard disks. If the filesystem is not loaded all the
time and leaves some idle slots for scrub, the idle class IO priority
is recommended. The idle class now is the default if the scrub
operation is started with the btrfs-progs tools.

Note that the patch that sets the scrub readahead IO priority to the
idle class is a seperate patch, this needs to be done in the kernel.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
2013-03-19 18:23:58 +01:00
David Sterba c535e2f7a7 btrfs-progs: makefile: clean static targets
* create .static.o version from the library objects as well and use them
  for building static targets
* remove build dependencies on libbtrfs.*
* other minor cleanups

Signed-off-by: David Sterba <dsterba@suse.cz>
2013-03-19 18:21:59 +01:00
Goffredo Baroncelli f243fcd1b2 Removing btrfsctl, btrfs-vol, btrfs-show
With the commit 002d021c (committed October 2011)
btrfsctl, btrfs-vol, btrfs-show were declared deprecated.
The last patches related to these commands are dated December 2010.

These tools are replaced by the "btrfs" tool in all the
functionality.

This commit removes all the related code.

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Signed-off-by: David Sterba <dsterba@suse.cz>
2013-03-19 18:21:41 +01:00
Sergei Trofimovich cf7e3472d7 Makefile: allow user set LDFLAGS for libbtrfs.so as well
Detected by gentoo's QA checker:

 * QA Notice: Files built without respecting LDFLAGS have been detected
 *  Please include the following list of files in your report:
 * /usr/lib/libbtrfs.so.0.1

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
2013-03-19 18:21:30 +01:00
Josef Bacik 87c09f70b5 Btrfs-progs: fix memory leaks on cleanup
I've been working on btrfs-image and I kept seeing these leaks pop up on
valgrind so I'm just fixing them.  We don't properly cleanup the device cache,
the chunk tree mapping cache, or the space infos on close.  With this patch
valgrind doesn't complain about any memory leaks running btrfs-image.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
2013-03-18 19:44:32 +01:00
Anand Jain e9393c220f btrfs-progs: defrag return zero on success
Signed-off-by: Anand Jain <anand.jain@oracle.com>
2013-03-18 19:42:29 +01:00
Josef Bacik 0c7136f8e0 Btrfs-progs: fix segfault when using tools fs with tree log
We just free the log root after we set it up when we open a ctree in the tools.
This isn't nice, it makes double free's and leaks eb's, makes segfaults with
btrfs-image.  So fix this to be correct, and fix the cleanup if the buffer is
not uptodate.  With this fix I no longer segfault trying to do btrfs-image on a
file system with a log tree.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
2013-03-18 19:41:58 +01:00
David Sterba 35ba8fc39e btrfs-progs: convert: access name_len and file_type the old way
We can't use ext2_dir_entry_2 typecast on big endian machines directly.
The bytes do not get converted during extX block read due to missing
flag EXT2_DIRBLOCK_V2_STRUCT passed down to ext2fs_read_dir_block4 from
ext2fs_process_dir_block. Fixing on the ext2 side needs updating callers
and (maybe) the library interfaces. We'll fix it on the convert side for
now.

CC: Jan Kara <jack@suse.cz>
Signed-off-by: David Sterba <dsterba@suse.cz>
2013-03-18 19:33:42 +01:00
Josef Bacik 7854c8b667 Btrfs-progs: give restore a list roots option
Since restore has the ability to open really really screwed up file systems, add
a list roots option to it so we can still get the contents of the tree root on a
horribly broken fs.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
2013-03-18 18:14:19 +01:00
Josef Bacik b268a41725 btrfs-progs: add lzo compression support to restore
This patch simply adds support to decompress lzo compressed extents in restore.

Signed-off-by: Josef Bacik <josef@redhat.com>
2013-03-18 18:14:19 +01:00
Peter Stuge 4ddd5874d9 restore: Split output directory and btrfs-local path search_dir() parameters
search_dir() recurses down the btrfs tree, and used to take the output
path for every item (i.e. in the running system, output root directory
concatenated with btrfs-local pathname) passed as the only path
parameter. Moving the output root directory to a separate parameter
and passing the btrfs-local pathname for each file and directory
separately allows easy filtering based on the btrfs-local pathname.

Signed-off-by: Peter Stuge <peter@stuge.se>
Signed-off-by: Josef Bacik <josef@redhat.com>
2013-03-18 18:14:19 +01:00
David Marcin c2839e123a btrfs-progs: Fix error handling for failed reads in restore tool when mirrors exist
Signed-off-by: David Marcin <djmarcin@google.com>
2013-03-18 18:14:18 +01:00
Josef Bacik 23bfbf0328 Btrfs-progs: try other mirrors on read failure
If we hit a bad disk and the read doesn't work, try other mirrors in case we
have other disks with good copies.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
2013-03-18 18:14:18 +01:00
Josef Bacik 9969ea479d Btrfs-progs: try other mirrors if decompression fails
This will make the restore program fall back on other mirrors if it fails to
decompress an extent for whatever reason.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
2013-03-18 18:14:10 +01:00
Josef Bacik 331295de05 Btrfs-progs: add an option for specifying the root to restore
If the normal fs tree is hosed and the user has multiple subvolumes it's handy
to be able to specify just one of the subvolumes to restore.  It's also handy if
a user only wants to restore say /home instead of his entire disk.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
2013-03-15 18:54:49 +01:00
Matias Bjørling 572343ae26 btrfs-progs: mkfs: add missing raid5/6 description
Signed-off-by: Matias Bjørling <m@bjorling.me>
2013-03-15 16:38:44 +01:00
Eric Sandeen c27d89f959 btrfs-progs: document force option in mkfs usage(); add long opt
I missed updating the mkfs.btrfs usage() when I added the
option to force fs overwrite.

Update that, and while we're at it add a long option, since
all other commands have long counterparts.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-03-14 23:46:18 +01:00
Anand Jain 44a33d0d14 btrfs-progs: print errno string when /dev/btrfs-control open fails
Of recently and intermittently I am seeing open fail
for /dev/btrfs-control (btrfs is loaded), and there are no
dmesg errors, this may not be a complete help in digging
this issue but something which is necessary.
Thanks

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2013-03-14 23:43:04 +01:00
Anand Jain b14d06ddb9 btrfs-progs: update .gitignore file
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2013-03-14 23:25:25 +01:00
Hugo Mills 84a42b7c71 btrfs-progs: add Makefile rule for static build of btrfs-find-root
btrfs-find-root isn't yet integrated into the main btrfs tool, and is
an important recovery tool, so it deserves to be built as a static
binary.

Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
2013-03-14 23:08:44 +01:00
Eric Sandeen 7a355379ea btrfs-progs: rework get_fs_info to remove side effects
get_fs_info() has been silently switching from a device to a mounted
path as needed; the caller's filehandle was unexpectedly closed &
reopened outside the caller's scope.  Not so great.

The callers do want "fdmnt" to be the filehandle for the mount point
in all cases, though - the various ioctls act on this (not on an fd
for the device).  But switching it in the local scope of get_fs_info
is incorrect; it just so happens that *usually* the fd number is
unchanged.

So - use the new helpers to detect when an argument is a block
device, and open the the mounted path more obviously / explicitly
for ioctl use, storing the filehandle in fdmnt.

Then, in get_fs_info, ignore the fd completely, and use the path on
the argument to determine if the caller wanted to act on just that
device, or on all devices for the filesystem.

Affects those commands which are documented to accept either
a block device or a path:

* btrfs device stats
* btrfs replace start
* btrfs scrub start
* btrfs scrub status

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-03-12 17:07:40 +01:00
Eric Sandeen 120fdfafa3 btrfs-progs: don't open-code mountpoint discovery in scrub cancel
cmd_scrub_cancel had its own mountpoint discovery routine;
just use open_path_or_dev_mnt() for that now.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-03-12 16:48:10 +01:00
Eric Sandeen 10e00b0764 btrfs-progs: three new device/path helpers
Add 3 new helpers:

* is_block_device(), to test if a path is a block device.
* get_btrfs_mount(), to get the mountpoint of a device,
  if mounted.
* open_path_or_dev_mnt(path), to open either the pathname
  or, if it's a mounted btrfs dev, the mountpoint.  Useful
  for some commands which can take either type of arg.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-03-12 16:44:40 +01:00
Eric Sandeen 5bc34c6602 btrfs-progs: close fd on return from label get/set functions
Somehow missed these 2 in the last round.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-03-12 16:34:41 +01:00
Josef Bacik 016f6f4354 Btrfs-progs: alloc our super copy in btrfs-find-root
Dave fixed the fs_info to allocate the super copy instead of embedding it, but
he failed to notice that I open code open_ctree in btrfs-find-root so we end up
with a super that's not allocated, so we segfault whenever you try to run
btrfs-find-root.  I've fixed this up and now we don't segfault anymore.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
2013-03-12 16:26:42 +01:00
Antoine Sirinelli 2648a11841 btrfs-progs: Add a rule to build a static mkfs.btrfs
Static mkfs.btrfs can be used to "bootstrap" a system from a live CD
which does not provide mkfs.btrfs.

The executable produced is named mkfs.btrfs.static and built by invoking
the "static" make rule.

Signed-off-by: Antoine Sirinelli <antoine@monte-stello.com>
2013-03-12 16:23:14 +01:00
David Sterba dd21bc16ad btrfs-progs: separate super_copy out of fs_info
Allocate fs_info::super_copy dynamically of full BTRFS_SUPER_INFO_SIZE
and use it directly for saving superblock to disk.

This fixes incorrect superblock checksum after mkfs.

Signed-off-by: David Sterba <dsterba@suse.cz>
2013-03-10 16:12:21 +01:00
Anand Jain fc61b53da8 btrfs-progs: update the .gitignore file
Signed-off-by: Anand Jain <anand.jain@oracle.com>
2013-03-10 16:06:38 +01:00
Eric Sandeen c3d5897555 btrfs-progs: fix scrub error return from pthread_mutex_lock
If pthread_mutex_lock() fails it returns the error in ret,
and does not set errno.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-03-10 16:06:37 +01:00
Eric Sandeen b79d4a217f btrfs-progs: Error handling in scrub_progress_cycle() thread
consolidate error handling to ensure that peer_fd
is closed on error paths.  Add a couple comments
to the error handling after the thread is complete.

Note that scrub_progress_cycle returns negative
errnos on any error.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-03-10 16:06:37 +01:00
Eric Sandeen 6626354fdf btrfs-progs: better option/error handling for btrfs-vol
Today wrong cmdlines give odd results:

	# ./btrfs-vol /dev/sdb1
	Unable to open device (null)
	# ./btrfs-vol -a /dev/sdb1
	usage: btrfs-vol [options] mount_point ...

Make it a bit more informative:

	# ./btrfs-vol /dev/sdb1
	No command specified
	usage: btrfs-vol [options] mount_point ...
	# ./btrfs-vol -a /dev/sdb1
	No mountpoint specified
	usage: btrfs-vol [options] mount_point ...

(even though it's deprecated ...)

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-03-10 16:06:37 +01:00
Eric Sandeen 7b81119b1d btrfs-progs: Issue warnings if ioctls fail in sigint handlers
The two sigint handlers issue ioctls to clean up, but if
they fail, noone would know.  I'm not sure there is
any other error handling to be done at this point, but a
notification seems wise.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-03-10 16:06:37 +01:00
Eric Sandeen 06efd54588 btrfs-progs: check return of posix_fadvise
It seems highly unlikely that posix_fadvise could fail,
and even if it does, it was only advisory.  Still, if
it does, we could issue a notice to the user.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-03-10 16:04:01 +01:00
Eric Sandeen b1d5f20c3a btrfs-progs: Free resources when returning error from cmd_subvol_create()
cmd_subvol_create() currently returns without freeing resources
in almost every error case.  Switch to a goto arrangement
so all cleanup can be done in one place.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-03-10 16:03:48 +01:00
Eric Sandeen 323318fd35 btrfs-progs: tidy up cmd_subvol_create() whitespace & returns
Just whitespace fixes, and magical return value removal.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-03-10 16:01:14 +01:00