Commit graph

608 commits

Author SHA1 Message Date
Mark Fasheh 1a72afaa85 btrfs-progs: mkfs support for extended inode refs
This patch turns on the BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF superblock flag
when creating a new file system in mkfs, enabling extended inode refs.

Signed-off-by: Mark Fasheh <mfasheh@suse.de>
2013-01-31 22:33:23 +01:00
Mark Fasheh 86279e7ef2 btrfs-progs: add extended inode ref support to btrfsck
Add a function, process_inode_extref() to be called from process_one_leaf()
when an item type of BTRFS_INODE_EXTREF_KEY is encountered.

Similarly to process_inode_ref(), process_inode_extref() walks an extref and
adds an inode_backref structure for each reference found within.

I modified fsck's inode_backref to get a type field (ref_type) which helps
us internally track the exact type of backrefs found.  Of course this field
could be overwritten in case of disk corruption (duplicate refs) but
duplicate refs themselves are tracked by btrfsck so that should not be an
issue as btrfsck is written today.

Signed-off-by: Mark Fasheh <mfasheh@suse.de>
2013-01-31 22:33:23 +01:00
Mark Fasheh 905b078928 btrfs-progs: Basic support for extended inode refs
This patch syncs the extended inode ref definitions from kernels ctree.h and
adds support in btrfs-debug-tree for visualizing the state of extended refs
on disk.

Signed-off-by: Mark Fasheh <mfasheh@suse.de>
2013-01-31 22:29:13 +01:00
Chen Yang 73355a60aa Btrfs-prog/send: fix wrong dump_fd check in cmd_send_start()
In cmd_send_start(), there is a check to make sure dump_fd is not a tty
before parsing command options. So if we use the option "-f file",
it doesn't work for the dump_fd has not been created. So fix it.

Signed-off-by: Cheng Yang <chenyang.fnst@cn.fujitsu.com>
2013-01-31 19:17:06 +01:00
Anand Jain 04af04e64f Btrfs-progs: man btrfs: subcommands must be grouped together
Signed-off-by: Anand Jain <anand.jain@oracle.com>
2013-01-31 19:14:43 +01:00
David Sterba 7aaf00fc2b btrfs-progs: fix parallel build
Parallel build may fail due to late creation of version.h, fix the rule name
that does not match the filename.

Signed-off-by: David Sterba <dsterba@suse.cz>
Reviewed-by: Eri Sandeen <sandeen@redhat.com>
2013-01-31 18:55:34 +01:00
Eric Sandeen 680a80ece1 btrfs-progs: fix mkfs.btrfs -r option
Commit 605e806166 broke the
mkfs.btrfs -r option, because it calls make_btrfs
without ever setting dev_block_count, in the -r case,
so we tell it to make a filesystem of size 0.

Then we wander into ENOSPC land and segfault.

As a quick one-line-fix, just set the dev_block_count
to the size of the destination image file.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-01-31 13:47:26 +01:00
Stefan Behrens 7e08a9116d Btrfs-progs: add support for device replace procedure
This is the user mode part of the device replace patch series.

The command group "btrfs replace" is added with three commands:
- btrfs replace start srcdev|srcdevid targetdev [-Bfr] mount_point
- btrfs replace status mount_point [-1]
- btrfs replace cancel mount_point

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
2013-01-31 13:47:26 +01:00
Stefan Behrens 5b8826ddfd Btrfs-progs: add command to get/reset device stats via ioctl
"btrfs device stats" is used to retrieve and print the device stats.
"btrfs device stats -z" is used to atomically retrieve, reset and
print the stats.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
2013-01-31 13:47:17 +01:00
Stefan Behrens 7a69dc4eec Btrfs-progs: make two utility functions globally available
Two convenient utility functions that have so far been local to scrub are
moved to utils.c.
They will be used in the device stats code in a following commit.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
2013-01-30 00:40:35 +01:00
Anand Jain 46e3b8087b Btrfs-progs: move open_file_or_dir() to utils.c
The definition of the function open_file_or_dir() is moved from common.c
to utils.c in order to be able to share some common code between scrub
and the device stats in the following step. That common code uses
open_file_or_dir(). Since open_file_or_dir() makes use of the function
dirfd(3), the required XOPEN version was raised from 6 to 7.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Original-Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
2013-01-30 00:40:35 +01:00
David Sterba 4a64455231 btrfs-progs: fix build warnings in btrfslabel.c
Signed-off-by: David Sterba <dsterba@suse.cz>
2013-01-30 00:40:35 +01:00
Ben Peddell 7b668965f0 btrfs-progs: fix unaligned accesses v2
gcc optimizes out the memcpy calls at -O2 and -Os.

Replacing memcpy with memmove does't work - gcc treats memmove
the same way it treats memcpy.

This patch brings in {get|put}_unaligned_le{16|32|64} (using the
packed struct method), and uses them in the failing get/set calls.

On architectures where unaligned accesses are cheap, these unaligned
macros should be optimized out by the compiler.

Signed-off-by: Ben Peddell <klightspeed@killerwolves.net>
2013-01-28 18:06:43 +01:00
Gene Czarcinski 272c049152 Btrfs-progs: Fix trival compiler error in cmds-qgroup.c
The compiler does not realize that usage() never returns.
Initializing the variable keeps it quiet.

Signed-off-by: Gene Czarcinski <gene@czarc.net>
2013-01-28 18:06:38 +01:00
Wang Sheng-Hui 7f04a61b6d btrfs-progs: update options in find-root.c
Remove the useless option "-v" and add the option "-o" in
the description of usage.

Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com>
2013-01-26 12:32:31 +01:00
Eric Sandeen 69af4b4ee2 btrfs-progs pretty/quiet build
A quieter build makes warnings more obvious.

This could probably be improved, but just to see
if people like this or if they hate it.  :)

make V=1 overrides it and gets you the full
glory again.

    [CC]     ctree.o
    [CC]     disk-io.o
    [CC]     radix-tree.o
    [CC]     extent-tree.o
    ...

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-01-26 12:32:24 +01:00
Josef Bacik 79e0e445fc btrfs-progs: kill check for /'s in labels
This patch kills a check in mkfs's label stuff which doesn't allow labels that
have /'s in them.  This causes problems for Anaconda which try to label volumes
with their mountpoints.  Thanks,

Signed-off-by: Josef Bacik <jbacik@redhat.com>
2013-01-25 23:38:31 +01:00
Anand Jain bbb9e4b419 Btrfs-progs: we need to have the string null terminated
Bug:
-------------
btrfs subvolume list / -a
ID 258 gen 4226 top level 384 path media/smbshare
::
btrfs subvolume list /home -a
ID 258 gen 4226 top level 5 path <FS_TREE>/__active/media/smbshare4.snap

In the first command's output, this path is printed correctly, however
in the second output it has "4.snap" appended, similar to the names of
the snapshots I made 22 hours ago.
------------

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reported-by: Brendan Hide <brendan@swiftspirit.co.za>
2013-01-25 22:45:39 +01:00
Chen Yang af7c373fdf Btrfs-prog/send: fix wrong best-parent assignment in, find_good_parent()
We use find_good_parent() to look for a suit snapshot in the clone source
snapshots as the parent, not the source subvolume of the snapshot which
is about to be sent. fix it

Reviewed-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
Signed-off-by: Cheng Yang <chenyang.fnst@cn.fujitsu.com>
2013-01-25 11:50:51 +01:00
Stefan Behrens c11d32446d btrfs-progs: Add btrfs-show-super
Just a small program to print the fields of a super block.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
2013-01-23 19:41:27 +01:00
Josef Bacik ce814a9378 Btrfs-progs: add btrfs device ready command
This command will be used by things like dracut that wish to know very
simply if all of the devices have been added to the kernel cache yet for the
device to be fully mounted.  This keeps initrd's from constantly having to
try to mount the file system until it succeeds every time a device is added
to the system.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Signed-off-by: Gene Czarcinski <gene@czarc.net>
2013-01-23 19:41:27 +01:00
Josef Bacik 124053b1d9 Btrfs-progs: detect if the disk we are formatting is a ssd
Patch rebased because of changes in mkfs.c but otherwise the same
as created by Josef Bacik

SSD's do not gain anything by having metadata DUP turned on.  The underlying
file system that is a part of all SSD's could easily map duplicate metadat
blocks into the same erase block which effectively eliminates the benefit of
duplicating the metadata on disk.  So detect if we are formatting a single
SSD drive and if we are do not use DUP.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Signed-off-by: Gene Czarcinski <gene@czarc.net>
2013-01-23 19:32:30 +01:00
Eric Sandeen 5cdc0913dd btrfs-progs: Use sysconf instead of getpagesize
Rawhide is getting cranky with posix compliance, and a few
things have stopped building.

getpagesize() is now only available -with- __USE_XOPEN_EXTENDED
or __USE_BSD, and NOT __USE_XOPEN2K.

_GNU_SOURCE must define __USE_XOPEN2K because getpagesize()
has gone away for mkfs.  I gave up and used sysconf.

Also, something used to pull in stat that no longer does, so
things like S_ISREG weren't getting defined.

The following fixes things for me.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-01-23 19:27:13 +01:00
Christian Hesse cdbe16b309 btrfs-progs: fix build, manpage compression command
man pages for btrfs-progs are compressed by gzip by default. In Makefile the
variable GZIP is use, this evaluates to 'gzip gzip' on my system. From man
gzip:

> The environment variable GZIP can hold a set of default options for gzip.
> These options are interpreted first and can be overwritten by explicit
> command line parameters.

So using any other variable name fixes this. Patch is attached.

Signed-off-by: Christian Hesse <list@eworm.de>
Signed-off-by: Gene Czarcinski <gene@czarc.net>
2013-01-23 18:37:44 +01:00
Andreas Fischer f2270bec86 Btrfs-progs: Fix typo in balance start usage; filetrs -> filters.
Fix typo in "btrfs balance start" usage documentation: 'filetrs' should have
been 'filters'.

Signed-off-by: Andreas Fischer <info@andreasfischer.net>
2013-01-22 16:58:43 +01:00
Stefan Behrens 5f3ab71103 Btrfs-progs: fix an off-by-one in write_dev_supers()
Fix an off-by-one in write_dev_supers().

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
2013-01-22 12:31:41 +01:00
Jan Schmidt db1b7f93b4 Btrfs-progs: bugfix for subvolume parent determination in btrfs send
We missed to add the default subvolume, because it has no ROOT_BACKREF_ITEM.
This made get_parent always fail for direct decendants of the default
subvolume, resulting in lots of full streams where incremental streams were
requested.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
Reviewed-by: Alexander Block <ablock84@googlemail.com>
2013-01-21 18:52:48 +01:00
Jan Schmidt cc088694ff Btrfs-progs: correcting misnamed parameter options for btrfs send
Unfortunately, the command line options for btrfs send were misnamed. The
-i option should not be used to give "clone sources", we'll be using -c
instead.

Compatibily note: -i option was broken anyway, which makes it less critical
renaming it. For potential users of the old option style, we emit a fatal
warning if the -i option is used.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
2013-01-21 18:52:34 +01:00
Arvin Schnell e02556d64a btrfs-progs: initialize data before send ioctl
Likely not strictly needed but I noticed valgrind complaining about
uninitialised memory in the ioctl call.

Signed-off-by: Arvin Schnell <aschnell@suse.de>
2013-01-21 18:37:50 +01:00
Wang Shilong 19def05127 Btrfs-progs: check the relation of two group by real level numbers
Comparing qgroupid is not good way to check the relationship of two groups,
the right way is to compare the real level numbers.

Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Gene Czarcinski <gene@czarc.net>
2013-01-21 18:28:01 +01:00
Wang Shilong 9886166880 Btrfs-progs: clean up reduplicate parse_qgroupid() and replace atoi with strtoull
1. parse_qgroupid() is implemented twice, clean up the reduplicate code.
2. atoi() can not detect errors, so use strtoull() instead of it.

Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Gene Czarcinski <gene@czarc.net>
2013-01-21 18:28:01 +01:00
Wang Shilong f933e084ea Btrfs-progs: fix arg parsing for btrfs qgroup limit commands
We can use this command in two ways.
1. btrfs qgroup limit size qgroupid path
2. btrfs qgroup limit size path

Before applying this patch, we differentiate them by check the parsing result
of the second argument. It is not so good because it may make some mistakes,
For example:
  btrfs qgroup limit 1M 123456
 			^ It is a subvolume name.

In fact, we can differentiate them just by the number of arguments, so fix it
by this way.

Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Gene Czarcinski <gene@czarc.net>
2013-01-21 18:28:01 +01:00
Ulrik c9597c7f17 Btrfs-progs: correct btrfs receive usage string
Fix the usage string to specify the correct '-f' option for input file,
not '-i'.

Signed-off-by: Ulrik Sverdrup <ulrik.sverdrup@gmail.com>
Signed-off-by: Gene Czarcinski <gene@czarc.net>
2013-01-21 18:28:00 +01:00
Nirbheek Chauhan abdb0ced01 Btrfs-progs: fix resolving of loop devices
The LOOP_GET_STATUS ioctl truncates filenames to 64 characters. We should get
the backing file for a given loop device from /sys/. This is how losetup does it
as well.

Signed-off-by: Nirbheek Chauhan <nirbheek.chauhan@collabora.co.uk>
Signed-off-by: Gene Czarcinski <gene@czarc.net>
Tested-By: Hector Oron <hector.oron@collabora.co.uk>
2013-01-21 18:28:00 +01:00
Danny Kukawka c88c2f52fe btrfs-progs: Handle errors returned from open_ctree
Signed-off-by: Danny Kukawka <danny.kukawka@bisect.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
2013-01-21 18:27:54 +01:00
Wang Sheng-Hui 0db197d8b2 btrfs-progs: add malloc check in transaction.h/btrfs_start_transaction
For malloc may fail, we should check it before assign
values to the struct btrfs_trans_handle *h.

Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com>
2013-01-18 18:27:21 +01:00
Arne Jansen 133e4520ea Btrfs-progs: bugfix for scrubbing single devices
Scrub can be invoked to scrub only a single device of a (mounted) filesystem.
The code determines whether the given path is a mountpoint of a filesystem
by issueing a btrfs-specific ioctl to it. Only in case of EINVAL it assumed
it may be a device, all other errnos just caused it fail, but some devices
(correctly) return ENOTTY. This patch adds this to the error check.

Signed-off-by: Arne Jansen <sensille@gmx.net>
2013-01-18 18:26:27 +01:00
Goffredo Baroncelli 681813b797 Ignore the error ENXIO and ENOMEDIUM during a devs scan
Ignore the error ENXIO (device don't exists) and ENOMEDIUM (
No medium found -> like a cd tray empty) in the function
btrfs_scan_one_dir.
This avoids spurios errors due to an empty CD or a block device node
without a device (which is frequent in a static /dev).

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
2013-01-18 18:25:50 +01:00
David Sterba 6cd836d7d9 btrfs-progs: ignore -a option in mkfs
Let mkfs accept '-a' option and not complain.  When a partition has non-zero
value in the fs_passno filed in /etc/fstab, the fsck is run but fails and boot
stops. As fsck does not break things currently, it's safe to ignore the option
and let the boot proceed.

Reference: https://bugzilla.novell.com/show_bug.cgi?id=655906

Signed-off-by: David Sterba <dsterba@suse.cz>
2013-01-17 18:34:40 +01:00
Simon Xu 4bd93ea68c btrfs-progs: remove '-h' from btrfs man page
Remove '-h' from btrfs man page as it's not supported by the btrfs utility.

Signed-off-by: Simon Xu <xu.simon@oracle.com>
2013-01-17 18:27:56 +01:00
Simon Xu 6c8bca9ae8 btrfs-progs: remove "device show" from btrfs man page
Remove "device show" from btrfs man page as it's not supported by the
btrfs utility.

Signed-off-by: Simon Xu <xu.simon@oracle.com>
2013-01-17 18:27:56 +01:00
Lluis Batlle i Rossell bb0eabc383 btrfs-progs: Fix getopt on arm platforms
There, 'char' is unsigned, so once assigned '-1' from getopt, it gets
the value 255. Then, it compared to '-1' gives false.

Signed-off-by: Lluis Batlle i Rossell <viric@viric.name>
2013-01-17 18:27:56 +01:00
Wang Sheng-Hui 8c5b2ae588 btrfs-progs: print the right mount checking info in restore.c
The mount status is checked against the arg <device> (argv[optind]),
not the <directory>. Correct the info printed on <device> mounted.

Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com>
2013-01-17 18:27:55 +01:00
Zach Brown 88016b0ee9 btrfs-progs: fix 32bit int/pointer cast warnings
This uses uintptr_t to cast pointers to u64 ioctl arguments to silence
some 32bit build warnings:

cmds-inspect.c: In function ‘__ino_to_path_fd’:
cmds-inspect.c:47:15: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
cmds-inspect.c: In function ‘cmd_logical_resolve’:
cmds-inspect.c:171:15: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]

Signed-off-by: Zach Brown <zab@redhat.com>
2013-01-17 18:27:55 +01:00
Kenji Okimoto 6e0e6c5e63 btrfs-progs: plug memory leaks in btrfs_scan_one_dir() reported by cppcheck.
[utils.c:983]: (error) Memory leak: fullpath

Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
2013-01-17 18:27:55 +01:00
Kenji Okimoto 1cce8d72f2 btrfs-progs: check malloc() result
Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
2013-01-17 18:27:55 +01:00
Kenji Okimoto 057d6ea34c btrfs-progs: plug a memory leak reported by cppcheck
[src/btrfs/disk-io.c:462]: (error) Memory leak: log_root

Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
2013-01-17 18:27:55 +01:00
Wang Sheng-Hui 6b972e6fa5 btrfs-progs: update usage description for debug-tree.c
There are more options than "-e" only.
Update the description for the usage.

Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com>
2013-01-17 18:27:55 +01:00
Goffredo Baroncelli 9495b4d228 parse_size(): add new suffixes
Add new suffixes in parse_size() function. New suffixes are: T as
terabyte, P as petabyte, E as exabyte. Note these units are
multiply of 2 .

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
2013-01-17 18:27:54 +01:00
Goffredo Baroncelli 6318867602 parse_size(): replace atoll() with strtoull()
Replace the function atoll with strtoull(); Check that the suffix for the
parse_size() input is of only one character.

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
2013-01-17 18:27:54 +01:00