Commit Graph

129 Commits (e4c6772f69bff7bb75d8df0d5010a1091d6e47eb)

Author SHA1 Message Date
Anand Jain d9a085ba83 Btrfs-progs: add subvol flags to print
This patch adds the flags row which as of now will show if the
subvol/snapshot is readonly.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
2013-02-01 16:55:06 +01:00
Anand Jain 28909327c3 Btrfs-progs: Fix a small memory leak in managing the btrfs list filter
Signed-off-by: Anand Jain <anand.jain@oracle.com>
2013-02-01 16:55:06 +01:00
Anand Jain 437eea9664 Btrfs-progs: add show subcommand to subvol cli
This adds show sub-command to the btrfs subvol cli
to display detailed inforamtion of the given subvol
or snapshot.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
2013-02-01 16:55:06 +01:00
Anand Jain e260954a9e Btrfs-progs: make printing subvol extensible to newer layouts
Currently you can print subvol in a list or table format.
This patch will provide a way to extend this to other formats
like the upcoming raw format.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
2013-02-01 16:55:05 +01:00
Anand Jain 89c899ed47 Btrfs-progs: add parent uuid for snapshots
Signed-off-by: Anand Jain <anand.jain@oracle.com>
2013-02-01 16:55:04 +01:00
Anand Jain 93b3fd3879 Btrfs-progs: move printing subvol list outside of btrfs_list_subvols
To improve the code reuse its better to have btrfs_list_subvols
just return list of subvols witout printing

Signed-off-by: Anand Jain <anand.jain@oracle.com>
2013-02-01 16:55:04 +01:00
Lukas Czerner 8c2b1be428 Btrfs-progs: List all subvolumes by default
Commit a1e89891eb changed subvolume list
command so that we list only subvolumes under the specified directory.
However this is confusing and unnecessary obstacle, because one usually
want to see all subvolumes in the file system. It was introduced with
the notion the full_path may be invalid which is not exactly true as the
full_path is always relative to the root subvolume which makes perfect
sense.

Simply making option '-a' default is not enough since it introduces the
relative/absolute path distinction effectively obfuscating the subvolume
nesting.

This commit returns the subvolume list command behaviour before commit
a1e89891eb where we list all subvolumes in
the filesystem with path naming from root subovolume. IMO this is the
best default as it is well understood and gives all the important
information about file system subvolumes including subvolume nesting
without the need to parse additional information.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
2013-02-01 16:55:03 +01:00
Lukas Czerner 6812036174 Btrfs-progs: add '-o' option into subvolume list command
This commit introduces new option '-o' to list only subvolumes under the
specified path. This does not change subvolume list  behaviour. It has
been default in the past and it is even with this commit.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
2013-02-01 16:55:03 +01:00
Lukas Czerner e599d6c5da Btrfs-progs: move path modification to filters
Commit 8e8e019e91 introduces -a option
which will list all subvolumes with distinguishing between relative and
absolute by prepending absolute patch with "<FS_TREE>".

This commit moves the path modification to a filter code rather than
doing so in path construction in resolve_root(). This gives us more
flexibility in formatting path output.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
2013-02-01 16:55:03 +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
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
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
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 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
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 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
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
Arne Jansen 89fe5b5f66 Btrfs progs: quota groups support
Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
Signed-off-by: Arne Jansen <sensille@gmx.net>
2012-09-04 11:15:49 +02:00
Chris Samuel dfb2230423 Fix "set-dafault" typo in cmds-subvolume.c
Andrei Popa reported that there were two typos of default as dafault,
this patch fixes those two typos up.

Signed-off-by: Chris Samuel <chris@csamuel.org>
2012-07-03 16:27:46 -04:00
Jim Meyering 8ad8e789fc mkfs: avoid heap-buffer-read-underrun for zero-length "size" arg
* mkfs.c (parse_size): ./mkfs.btrfs -A '' would read and possibly
write the byte before beginning of strdup'd heap buffer.  All other
size-accepting options were similarly affected.

Reviewed-by: Josef Bacik <josef@redhat.com>
2012-06-05 19:56:20 +01:00
Jim Meyering 54e345b5c2 avoid several strncpy-induced buffer overruns
* restore.c (main): Ensure strncpy-copied dir_name is NUL-terminated.
* btrfsctl.c (main): Likewise, for a command-line argument.
* utils.c (multiple functions): Likewise.
* btrfs-list.c (add_root): Likewise.
* btrfslabel.c (change_label_unmounted): Likewise.
* cmds-device.c (cmd_add_dev, cmd_rm_dev, cmd_scan_dev): Likewise.
* cmds-filesystem.c (cmd_resize): Likewise.
* cmds-subvolume.c (cmd_subvol_create, cmd_subvol_delete, cmd_snapshot):
Likewise.

Reviewed-by: Josef Bacik <josef@redhat.com>
2012-06-05 19:56:20 +01:00
Ilya Dryomov 08b51bd731 Btrfs-progs: allow multi-line command group synopsis
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
2012-02-08 18:55:51 +02:00
Ilya Dryomov d675085a67 Btrfs-progs: switch all existing commands to a new parser
The new infrastructure offloads checking number of arguments passed to a
command to individual command handlers.  Fix them up accordingly.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
2012-02-03 21:00:17 +02:00
Ilya Dryomov 4f26833193 Btrfs-progs: rearrange files in the repo
Separate every command group into its own file (cmds_<group>.c) and
rearrange includes.  Remove btrfs_cmds.c.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
2012-02-03 21:00:17 +02:00