Commit Graph

573 Commits

Author SHA1 Message Date
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
Goffredo Baroncelli
8f76aee6bc Move parse_size() to utils.[hc]
Move the function from cmds-filesystem.c and mkfs.c to utils.c

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
2013-01-17 18:27:54 +01:00
David Sterba
043437d8e1 btrfs-progs: do not send stream into a terminal
Signed-off-by: David Sterba <dsterba@suse.cz>
2013-01-17 18:27:54 +01:00
Alex Lyakas
e1a97972ac btrfs-progs: Receive: preserve ownership for symlinks, by using 'lchown'
Signed-off-by: Alex Lyakas <alex.btrfs@zadarastorage.com>
2013-01-17 18:27:54 +01:00
Arne Jansen
0b0a954e43 Btrfs-progs: fix unaligned accesses
There are some unaligned accesses in progs that cause malfunction or
crashes on ARM.
This patch fixes the ones we stumbled upon.

Signed-off-by: Arne Jansen <sensille@gmx.net>
2013-01-17 18:27:53 +01:00
Wang Sheng-Hui
bb2cfccf81 btrfs-progs: add -V description in print_usage
mkfs supports the option -V/--version.
Add its description to print_usage().

Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com>
2013-01-17 18:27:18 +01:00
Sergei Trofimovich
7385c8ab2c version.sh: fix version when built from tarball
[from 0.20-rc1 tarball]

Before the patch:
  $ ./btrfs --version
  Btrfs Btrfs v0.19

After the patch:
  $ ./btrfs --version
  Btrfs v0.20-rc1

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
2013-01-17 18:13:03 +01:00
Wade Cline
0d5cfddc2c Btrfs-progs: Fix compiler warnings on PPC64
The kernel uses unsigned long long for u64, but PPC64 uses unsigned
long by default. This results in compilation warnings such as:

print-tree.c:333: warning: format '%llu' expects type 'long long
unsigned int', but argument 4 has type 'u64'

To fix this, the macro __KERNEL__ needs to be defined before including
the file <asm/types.h>. This can be done by defining the macro in
"kerncompat.h" and making it the first included file in the relevant
header files; this fixes the compiler warnings on PPC64.

Reviewed-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Wade Cline <clinew@linux.vnet.ibm.com>
2013-01-17 18:12:57 +01:00
Chris Mason
91d9eec1ff Cast args to min to fix compiler warnings 2012-10-04 20:35:31 -04:00
Liu Bo
723e5b0f9a Btrfs-progs: add options to change bufsize in logical to inode translation
Add an option 's' to set bufsize in logical to inode transition, then we are able
to read all the refs to the logical address.
Meanwhile, set a max value 64k for the bufsize.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2012-10-04 20:33:20 -04:00
Goffredo Baroncelli
6eba900295 Correct un-initialized fsid variable 2012-10-04 20:32:19 -04:00
David Sterba
bc130ecd02 btrfs-progs: pretty print key in extent_item
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2012-10-04 16:26:34 -04:00
Anand Jain
6500965277 Btrfs-progs: btrfs subvolume delete could delete subvolumes
With this user will be able to provide more than one subvolume
to delete.
eg: btrfs subvolume delete <subvol1> <subvol2>

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2012-10-04 16:26:34 -04:00
Anand Jain
8ce1873c2a Btrfs-progs: correct the mkfs.btrfs man page
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2012-10-04 16:26:34 -04:00
Zhi Yong Wu
f38a139a96 btrfs-progs: Fix up memory leakage
Some code pathes forget to free memory on exit.

Changelog from v1:
  Fix the variable is used uncorrectly. [Ram Pai]

Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2012-10-04 16:26:34 -04:00
Zhi Yong Wu
4a39f7d5d1 btrfs-progs: Close file descriptor on exit
Need to close fd on exit.

Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2012-10-04 16:26:34 -04:00
Robin Dong
32be2a1164 btrfs-progs: limit the max value of leafsize and nodesize
Using mkfs.btrfs like:

        mkfs.btrfs -l 131072 /dev/sda

will return no error, but after mount it, the dmesg will report:

	BTRFS: couldn't mount because metadata blocksize (131072) was too large

The leafsize and nodesize are equal at present, so we just use one function
"check_leaf_or_node_size" to limit leaf and node size below BTRFS_MAX_METADATA_BLOCKSIZE.

Signed-off-by: Robin Dong <sanbai@taobao.com>
Reviewed-by: David Sterba <dave@jikos.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2012-10-04 16:26:34 -04:00
Goffredo Baroncelli
29db8b12cd pretty_sizes() returns incorrect values
pretty_sizes() returns incorrect values if the argument is < 1024.

pretty_sizes(0) -> 0.00		OK
pretty_sizes(102) -> 0.10	WRONG
pretty_sizes(1023) -> 1.00	WRONG
pretty_sizes(1024) -> 1.00KB	OK

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2012-10-04 16:26:33 -04:00
Wang Shilong
e86f7198d9 Btrfs-Progs: update '-s' option without a argument.
Since '--sort' options was given ,and we can list snapshots in generation
order by --sort=+/-gen to replace '-s [0|1]' totally.

Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujistsu.com>
2012-10-04 16:26:33 -04:00
Wang Shilong
8e8e019e91 Btrfs-progs: introduces '-a' option into subvolume list command
We list the subvolumes under current directory according to the input
subvolume.

However, if we still want to list all the subvolumes in the tree, we
can use '-a' option to help us.

There may be two kinds of path: absolute path , relative path .

The absolute path is beginning with "<FS_TREE>"
The relative path is under current path that you input.

Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
2012-10-04 16:26:33 -04:00
Wang Shilong
a1e89891eb Btrfs-Progs: fix subvolumes's some full_path invaild problems.
In the privous way, we list all the subvolumes in the filesystem default.

But if a subvolume mounts on another directory, some result's full_path
may be invaild.

According to this, we try to list subvolumes under directoy only by default.

In this way, all the subvolume can be arrived by the full_path.

Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
2012-10-04 16:26:33 -04:00
Miao Xie
0f53cf81f6 Btrfs-progs: introduce '-t' option into subvolume list command
This patch introduces '-t' option into subvolume list command. By this
option, we can output the result as a table.

Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
2012-10-04 16:26:33 -04:00
wangshilong
60d11eca66 Btrfs-progs: introduce -g -c --sort options into btrfs subvol list command
This patch introduces '-g' '-c' '--sort' options

The option '-g' can help you filter the subvolumes by the generation, you may
use it just like:

	btrfs subvol list -g +/-value <path>

'+' means the generation of the subvolumes should >= the value you specified.
'-' means the generation should <= the value
If you don't input either '+' nor '-', this command will list the subvolumes
that their generation equals to the value.

However if you want to find gengeration between value1 and value2
you may use the above like:

        btrfs sub list -g -value1 -g +value2 <path>

The option '-c' can help you filter the subvolumes by the ogeneration, you may
use it just like:

	btrfs subvol list -c +/-value <path>

The usage is the same to '-g'

You might want to list subvolumes in order of some items, such as root id, gen
and so on, you can use '--sort'. Now you can sort the subvolumes by root id,
gen, ogen and path.

For example:
If you want to list subvolumes in order of rootid, you can use the option like
that:

	btrfs sub list --sort=+/-rooid <path>

Here, '+' means the result is sorted by ascending order. '-' is by descending
order. If you don't specify either '+' nor '-', the result is sorted by
default - ascending order.

If you want to combine sort items, you do it like that:

	btrfs sub list --sort=-rootid,+path,ogen,gen <path>

Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
2012-10-04 16:26:33 -04:00
Zhou Bo
af3045cb20 Btrfs-progs: update the manpage entries for the btrfs subvolume list
This patch adds the introduction of the new option '-r' into the man page of
'btrfs subvolume list' command.

Signed-off-by: Zhou Bo <zhoub-fnst@cn.fujitsu.com>
2012-10-04 16:26:33 -04:00
Miao Xie
3defb82384 Btrfs-progs: enhance btrfs subvol list only to show read-only snapshots
We want 'btrfs subvolume list' only to list readonly subvolumes, this patch set
introduces a new option 'r' to implement it.

You can use the command like that:

        btrfs subvolume list -r <path>

Original-Signed-off-by: Zhou Bo <zhoub-fnst@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
2012-10-04 16:26:33 -04:00
Miao Xie
162df1e30c Btrfs-progs: restructure list_subvolumes
The current code of list_subvols() has very bad scalability, if we want to
add new filter conditions or new sort methods, we have to modify lots of code.

Beside that, the most code of list_snapshots() is similar to list_subvols(),

So I restructure list_subvols(), and split the subvolume filter function,
the subvolume sort function and the output function from list_subvols().
In order to implement it, we defined some importtant structures:
struct btrfs_list_filter {
	btrfs_list_filter_func filter_func;
	void *data;
};

struct btrfs_list_comparer {
	btrfs_list_comp_func comp_func;
	int is_descending;
};

struct {
	char	*name;
	char	*column_name;
	int	need_print;
} btrfs_list_columns[];

If we want to add a new filter condition, we can choose a suitable filter
function, or implement a new filter function[1], and add it into a set of
the filters, and then pass the filter set into list_subvols(). We also can
mix several filters (just add those filters into the set, and pass the set
into list_subvols()) if the users specify two or more filter conditions.

The subvolume sort function is similar to the subvolume filter function. The
differentiation is the order of comparers in the array which is passed into
list_subvols() show us the priority of the sort methods.

The output function is different with the above two functions, we define a
array to manage all the columns that can be outputed, and use a member variant
(->need_print) to control the output of the relative column. Some columns are
outputed by default. But we can change it according to the requirement of the
users.

After appling this patch, we needn't implement a independent list_snapshots()
function, just pass a filter function which is used to identify the snapshot
into list_subvols().

[1]: If we implement new filter functions or compare functions, we must add
them into the array all_filter_funcs or the array all_comp_funcs, and modify
the relative enum variants(btrfs_list_filter_enum, btrfs_list_comp_enum).

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
2012-10-04 16:26:32 -04:00
Miao Xie
7cb1cf7542 Btrfs-progs: fix wrong way to check if the root item contains otime and uuid
Now we check if the root item contains otime and uuid or not by comparing
->generation_v2 and ->generation of the btrfs_root_item structure, it is
wrong because it is possbile that ->generation may equal to the first
variant of the next item. We fix this problem by check the size of btrfs_root_item,
if it is larger than the original one, the new btrfs_root_item contains otime
and uuid. we needn't worry the case that the new filesystem is mounted on the
old kernel. because the otime and uuid are not changed on the old kernel, we can
get the correct result even on the kernel.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
2012-10-04 16:26:32 -04:00
Miao Xie
f0d08f254c Btrfs-progs: fix wrong usage of btrfs subvolume list command
Since the uuid output function has been implemented, we should update
the usage to tell the users.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
2012-10-04 16:26:32 -04:00
Miao Xie
f25d8564dc Btrfs-progs: fix compile warning of implicit declaration of "list_snapshots"
This patch fixes the following warning:
cmds-subvolume.c:283:3: warning: implicit declaration of function "list_snapshots"

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
2012-10-04 16:26:32 -04:00
Zhou Bo
c5800fb016 Btrfs-progs: move the function declarations to a new head file
Move the function declarations to a new head file.

Signed-off-by: Zhou Bo <zhoub-fnst@cn.fujitsu.com>
2012-10-04 16:26:32 -04:00
Anand Jain
f4dfc8f6ed Btrfs-progs: seg fault in get_label_unmounted
btrfs f l /
No valid Btrfs found on /
Segmentation fault (core dumped)

open_ctree can return NULL, we need to check that.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
2012-10-04 16:26:32 -04:00
Anand Jain
8a25bb834b Btrfs-progs: add -u to show subvol uuid
Applications would need to know the uuid to manage the configurations
associated with the subvol and snapshots

Signed-off-by: Anand Jain <anand.jain@oracle.com>
2012-10-04 16:26:32 -04:00
Anand Jain
2e6bcfac11 Btrfs-progs: add otime to the snapshot list
Reviewed-by: Alexander Block <ablock84@googlemail.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
2012-10-04 16:26:32 -04:00
Liu Bo
f02827c1c0 Btrfs-progs: list snapshots by generation
The idea is that we usually use snapshot to backup/restore our data, and the
common way can be a cron script which makes lots of snapshots, so we can end
up with spending some time to find the latest snapshot to restore.

This adds a feature for 'btrfs subvolume list' to let it list snapshots by their
_created_ generation.

What we need to do is just to list them in descending order and get the latest
snapshot.  What's more, we can find the oldest snapshot as well by listing
snapshots in ascending order.

Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
2012-10-04 16:26:32 -04:00
Liu Bo
95eeaf1c29 Btrfs-progs: show generation in command btrfs subvol list
This adds the ability to show root's modification generation when we use
btrfs subvol list.

NOTE:
Like file's atime and ctime, root's generation also has 'creation generation'
and 'modification generation'.
The generation that we're going to show is 'modification generation', and the
next patch is going to show 'creation generation'.

Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
2012-10-04 16:26:32 -04:00
Liu Bo
a8975893cf Btrfs-progs: search subvolumes with proper objectid
Btrfs's subvolume/snapshot is limited to
[BTRFS_FIRST_FREE_OBJECTID, BTRFS_LAST_FREE_OBJECTID], so just apply the range.

Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
2012-10-04 16:26:31 -04:00