Commit Graph

1714 Commits (39568fa417ceee3133a8cadae0bd1527adf61221)
 

Author SHA1 Message Date
Qu Wenruo 7c7fd19b8d btrfs-progs: Fix memleak in get_raid56_used()
Fix memleak in get_raid56_used().

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-04 16:48:09 +01:00
Gui Hecheng 07f114307f btrfs-progs: cleanup dead return after usage() for fi-disk_usage
The usage() calls exit() internally, so remove the return after it.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-04 16:48:09 +01:00
Goffredo Baroncelli 330903d4ee btrfs-progs: Add btrfs device disk-usage command
Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-04 16:48:09 +01:00
Goffredo Baroncelli 9002666a2b btrfs-progs: Add command btrfs filesystem disk-usage
Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-04 16:48:09 +01:00
Goffredo Baroncelli cbda6f2527 btrfs-progs: Add helpers functions to handle the printing of data in tabular format
This patch adds some functions to manage the printing of the data in
tabular format.

The function
	struct string_table *table_create(int columns, int rows)
creates an (empty) table.

The functions
	char *table_printf(struct string_table *tab, int column,
		int row, char *fmt, ...)
	char *table_vprintf(struct string_table *tab, int column,
		int row, char *fmt, va_list ap)
populate the table with text. To align the text to the left, the text
shall be prefixed with '<', otherwise the text shall be prefixed by a
'>'. If the first character is a '=', the the text is replace by a
sequence of '=' to fill the column width.

The function
	void table_free(struct string_table *)
frees all the data associated to the table.

The function
	void table_dump(struct string_table *tab)
prints the table on stdout.

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-04 16:48:09 +01:00
Goffredo Baroncelli e12e91e859 btrfs-progs: Enhance the command btrfs filesystem df
Enhance the command "btrfs filesystem df" to show space usage information
for a mount point(s). It shows also an estimation of the space available,
on the basis of the current one used.

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
[code moved under #if 0 instead of deletion]
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-04 16:48:09 +01:00
David Sterba 3d1ed6d152 btrfs-progs: move group type and profile pretty printers to utils
Move and add the btrfs_ prefix.

Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-04 16:48:09 +01:00
David Sterba e4c12281c2
Btrfs progs 3.17.3
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-04 14:47:18 +01:00
Qu Wenruo 1102b3483b btrfs-progs: print root dir verbose error in fsck
Before this patch, when btrfsck found an error in root dir, it will only
output the following message "root %llu root dir %llu error" without any
detailed error.

Just add print_inode_error() to print out the whole error.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-04 14:37:44 +01:00
Chandan Rajendra 602536773d Btrfs-progs: add_refs_for_implied: Use root_id instead of root_bytenr.
resolve_one_root() returns the objectid of a tree rather than the logical
address of the root node. Hence using root_bytenr is misleading. Fix this.

Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-27 18:37:05 +01:00
Gui Hecheng 8be2fff129 btrfs-progs: apply realpath for btrfs fi show when mount point is given
For now,
	# btrfs fi show /mnt/btrfs
gives info correctly, while
	# btrfs fi show /mnt/btrfs/
gives nothing.

This implies that the @realpath() function should be applied to
unify the behavior.

Made a more clear comment right above the call as well.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-27 18:37:00 +01:00
Gui Hecheng 05afee3468 btrfs-progs: fix return value problem for btrfs sub show
If you exec:
	# btrfs sub show <dir>	<== non-subvolume dir
The cmd print error messages as expected, but returns 0.
By convetion, it should return non-zero and we should explicitly
set it before it goto out.

With other pieces adopted:
1) removed a unnecessary return value set -EINVAL
2) fixed another code branch which may return 0 upon error.
3) with 2) applied, the ret = 0 follows can be removed

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-27 18:36:55 +01:00
David Sterba 15ed5e2a91 btrfs-progs: fix spacing in error messages
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-25 19:50:12 +01:00
Liu Bo ad96e8f4d6 Btrfs-progs: fix a bug of converting sparse ext2/3/4
When converting a sparse ext* filesystem, btrfs-convert adds checksum extents
for empty extents, whose disk_bytenr = 0, and this can end up with some weird
problems, one of them is the failure of reading free space cache inode on
mounting converted btrfs.

The fix is simple, just to skip making checksum on empty extents.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-25 19:39:44 +01:00
Eryu Guan b5e1ca5a49 btrfs-progs: add new dev replace result
A new dev replace result was introduced by kernel commit

Btrfs: return failure if btrfs_dev_replace_finishing() failed

Make the userspace know about the new result too.

Signed-off-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-25 18:50:58 +01:00
David Sterba c38aa53268
Btrfs progs v3.17.2
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-19 17:44:56 +01:00
David Sterba 7560f46ea9 btrfs-progs: use system attr instead of attr library
We use the attr version provided by system in other places already,
now we can remove dependency on the separate attr library.

Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-19 14:42:17 +01:00
Christian Hesse 5bfc3fea81 btrfs-progs: fix compiler warning
gcc 4.9.0 gives a warning: array subscript is above array bounds

Checking for "greater or equal" instead of just "equal" fixes this.

The warning is a false positive, appears with -ftree-vrp, but we'd
rather fix it to avoid noise during build.

http://www.mail-archive.com/linux-btrfs%40vger.kernel.org/msg34338.html

Signed-off-by: Christian Hesse <mail@eworm.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-18 18:25:58 +01:00
David Sterba 5ebf59ff58 btrfs-progs: use proper size for argv0 substitution
Make run from a long base path will overflow the argv0 buffer during
tests. Otherwise, this would happen for all the standalone binaries that
use set_argv0.

Original report:
https://bbs.archlinux.org/viewtopic.php?id=189861

Reported-by: WorMzy Tykashi <wormzy.tykashi@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-18 18:05:20 +01:00
Gui Hecheng a1c3bcf1c2 btrfs-progs: use canonical name for device in btrfs fi show when mounted
When using lvm volumes to check fstests: btrfs/006, it fails like:
     Label: 'TestLabel.006'  uuid: <UUID>
     	Total devices <EXACTNUM> FS bytes used <SIZE>
     	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
    +	devid <DEVID> size <SIZE> used <SIZE> path /dev/dm-4
    +	devid <DEVID> size <SIZE> used <SIZE> path /dev/dm-5
    +	devid <DEVID> size <SIZE> used <SIZE> path /dev/dm-6

The /dev/dm-* points to lvm volumes, use @canonicalize_path() to convert them
and we will make it through. Of course we should do the same thing for dev stat.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-14 11:02:33 +01:00
Qu Wenruo 0c44c195fe btrfs-progs: Check sb_bytenr with device size before scanning one device.
When using btrfs check with -s option, if using '-s 2' on a small
device which doesn't have the third superblock, "No valid Btrfs found"
will be output, but it is not appropriate.

So check sb_bytenr against device size before scanning a device and
output proper error message.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-14 11:02:16 +01:00
Josef Bacik 1e3da6d65e Btrfs-progs: test images for new btrfsck functionality
These test the recreating of missing dir item/dir index pairs, fixing the no
rootdir inode item and no inode item for normal files.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
2014-11-14 11:01:57 +01:00
Josef Bacik e4e7058173 Btrfs-progs: create missing root dirid
If we just don't have the root dirid stuff go ahead and re-create it, since it
is easily recreated.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-14 11:01:38 +01:00
Josef Bacik 9151febadd Btrfs-progs: fix missing inode items
If we have all the other items but no inode item we can recreate it for the most
part, with the exception of the permissions and ownership.  Add this ability to
btrfsck.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-14 11:01:24 +01:00
Josef Bacik 2dc4c0015f Btrfs-progs: add ability to replace missing dir item/dir indexes
If we have everything except the dir item and dir index we can easily replace
them, so add this ability to btrfsck.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-14 11:00:43 +01:00
Josef Bacik 2d80d0d645 Btrfs-progs: add a message to know zero log ran successfully
If there are errors when opening the fs because of PARTIAL we could think that
the zero-log didn't actually work.  Add a printf so we know that it was
successfull.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-14 11:00:32 +01:00
Josef Bacik 748f4dedbb Btrfs-progs: make zero-log use partial open
Because seriously, we only want to kill the tree log.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-14 11:00:28 +01:00
Josef Bacik 6d6a3e7991 Btrfs-progs: spit out the broken file when ignoring errors
It's nice to ignore errors on restore, but spit out the filename so the user
knows which files of his aren't going to look right.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-14 11:00:24 +01:00
Josef Bacik 4fa068bcdb Btrfs-progs: don't fail on log tree opening with PARTIAL
We were failing to fsck a volume because we couldn't open the log tree, which is
not helpful.  Make us skip erroring out if we are using OPEN_CTREE_PARTIAL since
it isn't a mandatory tree.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-14 11:00:17 +01:00
Josef Bacik 183a9d4537 Btrfs-progs: add the ability to delete items
Somtetimes you just need to delete an item, add that functionality to
btrfs-corrupt-block.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-14 10:59:11 +01:00
Christian Hesse 5676e94ad8 btrfs-progs: fix compiler warning
gcc 4.9.0 gives warnings about possibly uninitialized values when
compiling with function inlining and optimization level two enabled
(CFLAGS="-finline-functions -O2").

Initializing the values fixes the warning. Hope this is correct.

Signed-off-by: Christian Hesse <mail@eworm.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-07 18:14:38 +01:00
David Sterba 3d0b0111df btrfs-progs: update .gitignore
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-07 17:59:56 +01:00
David Sterba 6d95e999ad btrfs-progs: build, update the clean rule
Remove duplicate files, add extra progs, add library test binaries.

Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-07 17:52:58 +01:00
David Sterba 3fba49eab8 btrfs-progs: build, gather utilities that are not built by default
Add them to build test and to clean rules.

Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-07 17:52:58 +01:00
David Sterba 86be0aeaf6 btrfs-progs: build, add make target for a build test
A quick check that everything still builds.

Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-07 17:52:58 +01:00
David Sterba effebebb42 btrfs-progs: build, add basic build test for library
Basic test based on snapper code that uses the send stream API.

Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-07 17:52:57 +01:00
David Sterba 5005192611
Btrfs progs v3.17.1
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-04 18:30:34 +01:00
David Sterba 0287f03a8c btrfs-progs: use the correct SI prefixes
The SI standard defines lowercase 'k' and uppercase for the rest.

Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-04 18:22:51 +01:00
David Sterba cafacda441 btrfs-progs: libbtrfs, make exported headers compatible with C++
Add externs and don't use a reserved keyword.

Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-03 23:50:50 +01:00
Anand Jain 2f55fd7019 btrfs-progs: optimize btrfs_scan_lblkid() for multiple calls
btrfs_scan_lblikd() is called by most the device related command functions.
And btrfs_scan_lblkid() is most expensive function and it becomes more expensive
as number of devices in the system increase. Further some threads call this
function more than once for absolutely no extra benefit and the real waste of
resources. Below list of threads and number of times btrfs_scan_lblkid()
is called in that thread.

  btrfs-find-root            1
  btrfs rescue super-recover 2
  btrfs-debug-tree           1
  btrfs-image -r             2
  btrfs check                2
  btrfs restore              2
  calc-size                  NC
  btrfs-corrupt-block        NC
  btrfs-image                NC
  btrfs-map-logical          1
  btrfs-select-super         NC
  btrfstune                  2
  btrfs-zero-log             NC
  tester                     NC
  quick-test.c               NC
  btrfs-convert              0
  mkfs                       #number of devices to be mkfs
  btrfs label set unmounted  2
  btrfs get label unmounted  2

This patch will:
  move out calling register_one_device with in btrfs_scan_lblkid()
  and so function setting the BTRFS_UPDATE_KERNEL to yes will
  call btrfs_register_all_devices() separately.

  introduce a global variable scan_done, which is set when scan is
  done succssfully per thread. So that following calls to this function
  will just return success.

  Further if any function needs to force scan after scan_done is set,
  then it can be done when there is such a requirement, but as of now there
  isn't any such requirement.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-03 19:17:11 +01:00
Anand Jain 53cb7fbe8d btrfs-progs: introduce btrfs_register_all_device()
This function is to register all devices found after scanning
the system. Before we had this functionality with in the
btrfs_scan_lblkid(), however scanning and registering are two
different distinct operation its better keep them separate.
Also we want to optimize btrfs_scan_lblkid and avoid multiple
system scans unless needed. As of now device scan uses this function.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-03 19:17:08 +01:00
David Sterba dcf11c371c btrfs-progs: fix linking with libbtrfs
Reported at https://github.com/openSUSE/snapper/issues/128

Commit cdb9e22e29 added another rbtree file that defines
functions that libbtrfs uses.

Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-03 18:42:34 +01:00
Qu Wenruo 0f70b67a0c btrfs-progs: Fix the argument requirement for '--subvol-extents'
The following commit changed the argument requirement for
'--subvol-extents', which causes it to call arg_strtou64() on NULL,
resulting a segfault.
d34cbe76 btrfs-progs: check: do not require argument for --subvol-extents

This patch revert the patch and change the help string and man page to
make it no longer confusing.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-03 18:35:31 +01:00
Gui Hecheng 8a26f850cd btrfs-progs: skip mounted fs when deal with umounted ones for fi show
Stalling problems may happen when exec balance & fi show cmds concurrently.

With the following commit:
        commit 915902c500
        btrfs-progs: fix device missing of btrfs fi show with seed devices

The fi show cmd will bother the mounted fs when only umounted fs should
be handled after @btrfs_can_kernel() has finished showing all mounted ones.

We could skip the mounted fs after @btrfs_can_kernel() is done, then tasks
keeps going on mounted fs while fi show continues on umounted ones separately.

Reported-by: Petr Janecek <janecek@ucw.cz>
Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-03 18:35:31 +01:00
Anand Jain cfdb818dda revert btrfs-progs: do a separate probe for _transient_ replacing device
There is a compatibility issue with older kernel with the progs commit id as below.

d0588bfa47
btrfs-progs: do a separate probe for _transient_ replacing device

So as of now writing to revert the above commit id.
The brewing sysfs interface would help to fix the impending issue, which is
seed device would fail show in 'btrfs fi show' output of a sprout device.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-03 18:35:30 +01:00
Qu Wenruo ae8f7f687f btrfs-progs: Fix number of arguments check of 'btrfs fi df'
'btrfs fi df' needs exactly one arguments as mount option,
but as 3.17 we can run 'btrfs fi df' without any argument,
and it will error as "ERROR: can't access '%s'" which means
the argument number does not do what it should.

The bug is caused by manually modify the optind and use check_argc_max()
instead of the original check_argc_exact().

This patch fixes it by not modifying the optind and use check_argc_exact()
again.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-03 18:35:30 +01:00
Zach Brown 34ed841dcd btrfs-progs: fix csum root copy-n-paste error
btrfs_setup_all_roots() had some copy and pasted code for trying to
setup a root and then creating a blank node if that failed.  The copy
for the csum_root created the blank node in the extent_root.

So we create a function to use a consistent root.

Signed-off-by: Zach Brown <zab@zabbo.net>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-03 18:35:30 +01:00
Zach Brown 85d67ac145 btrfs-progs: check read extent errors when mapping
coverity barked out a warning that btrfs-map-logical was storing but
ignoring errors from read_extent_from_disk().   So don't ignore 'em.  I
made extent reading errors fatal to match the fatal errors from mapping
mirrors above.

And while we're at it have read_extent_from_disk() return -errno pread
errors instead of -EIO or -1 (-EPERM).  The only other caller who tests
errors clobbers them with -EIO.

Signed-off-by: Zach Brown <zab@zabbo.net>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-03 18:35:30 +01:00
Anand Jain 9662864435 btrfs-progs: code optimize cmd_scan_dev() use btrfs_register_one_device()
cmd_scan_dev() has it own code to register device (calling ioctl
BTRFS_IOC_SCAN_DEV), apparently it could use btrfs_register_one_device().

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-03 18:35:30 +01:00
Eryu Guan 39893bb15e btrfs-progs: only report internal dev replace result if there's a result
If BTRFS_IOC_DEV_REPLACE ioctl failed, args.result usually won't be
updated by the ioctl.

And the arg has been initialized with 0, the result is always 0, which
is BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR, and the resulting error
message looks confusing:

ERROR: ioctl(DEV_REPLACE_START) failed on "/mnt/btrfs": No such file or directory, no error

But in case there's an internal result returned in future, don't drop
the result completely, instead print dev replace result message only
if the result is updated by a failed ioctl call.

Signed-off-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-03 18:35:30 +01:00