Commit Graph

129 Commits (e4c6772f69bff7bb75d8df0d5010a1091d6e47eb)

Author SHA1 Message Date
Martin Volf 3b7a87d795 btrfs-progs: Remove redundant short description from cmd_snapshot_usage
cmd_snapshot_usage in cmds-subvolume.c contains the short description
twice. Remove the first one.

Signed-off-by: Martin Volf <martin.volf.42@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-01-14 02:20:26 +01:00
David Sterba 1519ee3f58 btrfs-progs: subvol delete: rename variable to match the option name
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-10 16:04:08 +01:00
David Sterba 2ed161bd28 btrfs-progs: subvol delete: add verbosity option
Add an the option -v and use it for the transaction commit mode message.

Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-10 16:04:04 +01:00
David Sterba 47bbff777e btrfs-progs: let subvol delete print commit mode inline
There are options to specify if the subvolume deletion should wait for
commit after each subvol or at the end. This is reported at the
beginning and considered as a noise. We'd like to report the mode for
each subvolume instead.

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

Reported-by: Marc MERLIN <marc@merlins.org
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-10 15:46:17 +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 6420192e87 btrfs-progs: wait until all subvolumes are cleaned
Enhance the 'subvolume' subcommand to wait until a given list of
subvolumes or all currently scheduled for deletion are cleaned
completely from the filesystem.

Signed-off-by: David Sterba <dsterba@suse.cz>
2014-10-10 09:32:05 +02:00
Hugo Mills 90a379a876 btrfs-progs: Add -R to list UUIDs of original received subvolume
When using send/receive, it it useful to be able to match up source
subvols on the send side (as, say, for -p or -c clone sources) with their
corresponding copies on the receive side. This patch adds a -R option to
btrfs sub list to show the received subvolume UUID on the receive side,
allowing the user to perform that matching correctly.

Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-09-14 13:09:52 +02:00
Hugo Mills 2be623dbae btrfs-progs: Fix spelling in btrfs sub list help
"below", not "bellow"

Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-08-22 16:09:55 +02:00
Satoru Takeuchi c2d83207bf btrfs-progs: move test_isdir() to utils.c
Since test_isdir() is a utility function, it's better to
move it to utils.c. In addition, "const char *" is
more appropriate type as its "path" argument because
this argument is not changed in this function.

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Cc: David Sterba <dsterba@suse.cz>
Cc: Mike Fleetwood <mike.fleetwood@googlemail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-08-22 15:07:04 +02:00
Satoru Takeuchi 91b3334057 btrfs-progs: introduce test_issubvolname() for simplicity
There are many duplicated codes to check if the given string is
correct subvolume name. Introduce test_issubvolname() for this
purpose for simplicity.

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Cc: David Sterba <dsterba@suse.cz>
Cc: Mike Fleetwood <mike.fleetwood@googlemail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-08-22 15:07:04 +02:00
Satoru Takeuchi 6452351060 btrfs-progs: Unify the messy error message formats
Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-08-22 15:07:03 +02:00
Qu Wenruo de22c28ef3 btrfs-progs: Check fstype in find_mount_root()
When calling find_mount_root(), caller in fact wants to find the mount
point of *BTRFS*.

So also check ent->fstype in find_mount_root() and do special error
string output in caller.

This will suppress a lot of "Inapproiate ioctl for device" error
message.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-08-22 15:07:02 +02:00
Wang Shilong 64fddab8ac Btrfs-progs: switch to arg_strtou64() part3
Switch to new helper arg_strtou64(), also check if user assign
a valid super copy.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
2014-03-21 06:23:20 -07:00
Wang Shilong cf822f5dba Btrfs-progs: fix double free when deleting subvolumes
Steps to reproduce:
	# mkfs.btrfs -f /dev/sda8
	# mount /dev/sda8 /mnt
	# btrfs sub create /mnt/a
	# touch /mnt/b
	# btrfs sub create /mnt/c
	# btrfs sub delete /mnt/*

Above steps will trigger following abortion:

ERROR: 'b' is not a subvolume
*** Error in `btrfs': double free or corruption (out): 0x0000000002116060 ***
======= Backtrace: =========
/lib64/libc.so.6[0x3fa467cef8]
/lib64/libc.so.6(closedir+0xd)[0x3fa46b846d]
btrfs[0x43e608]
btrfs[0x40622f]
btrfs[0x403d19]
btrfs[0x4062c6]
btrfs[0x403f68]

We try to fix it by resetting @fd && @dirstream before trying next
subvolume deletion.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
2014-01-31 08:22:29 -08:00
Mitchel Humpherys ef3f6124f0 btrfs-progs: fix minor grammar issues
Remove the extraneous `to' from `Can't access to X'.

Signed-off-by: Mitchel Humpherys <mitch.special@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
2014-01-31 08:22:28 -08:00
David Sterba 4b7656f3bf btrfs-progs: add options to set commit mode after subvol delete
Subvolume deletion does not do a full transaction commit. This can lead
to an unexpected result when the system crashes between deletion and
commit, the subvolume directory will appear again. Add options to request
filesystem sync after each deleted subvolume or after the last one.

If the command with --commit option finishes succesfully, the
subvolume(s) deletion status is safely stored on the media.

Userspace approach is more flexible than in-kernel. Related discussions:
http://www.spinics.net/lists/linux-btrfs/msg22088.html
http://www.spinics.net/lists/linux-btrfs/msg27240.html

CC: Alex Lyakas <alex.btrfs@zadarastorage.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
2014-01-31 08:22:20 -08:00
Gui Hecheng 3cae13ee93 btrfs-progs: remove NULL-ptr judge before free for btrfs-progs
free(3) already checks the pointer for NULL, no need to do it
on your own. This patch make the change globally.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
2014-01-31 08:22:17 -08:00
Anand Jain 1ecefced86 btrfs-progs: define BTRFS_UUID_UNPARSE_SIZE for uuid unparse buf size
we use 37 as the allocation size to hold the uuid_unparse, here
it defines BTRFS_UUID_UNPARSE_SIZE for the same.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
2014-01-31 08:22:03 -08:00
Eric Sandeen 83e941a746 btrfs-progs: fix potential double-frees in cmd_subvol_delete()
If we "goto again" in cmd_subvol_delete(), and error out to out:
before re-allocating the dupdname and dupvname pointers, we'll
double-free them.

Set them to NULL after freeing to avoid this.

Resolves-Coverity-CID: 1125944
Resolves-Coverity-CID: 1125945
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-11-07 16:10:40 -05:00
Eryu Guan 55d3729d4c Btrfs-progs: set return value to 0 if subvolume get-default successfully
cmd_subvol_get_default() returns 1 even if finds default subvolume
successfully.

Set the correct return value.

Signed-off-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-11-07 16:10:40 -05:00
David Sterba 4fc17596aa btrfs-progs: add filter for deleted but uncleanded subvolumes
New option to subvolume list that acts as a global filter and applies
the other filters to either live subvolumes or the uncleaned ones.

The path to the deleted subvolumes is lost at the deletion time, sample
output looks like:

ID 259 gen 7 top level 0 path <FS_TREE>/DELETED

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-10-24 05:57:44 -04:00
Eryu Guan a7131ad124 Btrfs-progs: check return value of realpath(3)
I hit a segfault when deleting a subvolume with very long name(>4096),
it's because cmd_subvol_delete() calls strdup() and passes NULL as
argument, which is returned by realpath(3).

I used the following script to reproduce

	#!/bin/bash
	mnt=$1
	i=1
	path=$mnt/subvol_$i

	# Create very deep subvolumes
	while btrfs sub create $path;do
	      ((i++))
	      path="$path/subvol_$i"
	done
	last_vol=$(dirname $path)
	dir=$(dirname $last_vol)
	vol=$(basename $last_vol)

	# Try to delete tha last one, this would get segfault
	pushd $dir
	btrfs sub delete $vol
	popd

Fix it by checking return value of realpath(3), also fix the one in
find_mount_root().

Signed-off-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-10-16 08:23:13 -04:00
chandan c31c50f330 btrfs-progs: cmd_find_new: Sync fs before searching for modified files.
The sync makes sure that 'very recently' introduced delayed work is
accounted for in the output of 'btrfs subvolume find-new' command.

Signed-off-by: chandan <chandan@linux.vnet.ibm.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-10-16 08:23:11 -04:00
Gui Hecheng 1c87a95bfc btrfs-progs: free strdup()s that are not freed
The strdup()s not freed are reported as memory leaks by valgrind.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-10-16 08:20:42 -04:00
Wang Shilong 2f041d9915 Btrfs-progs: fix magic return value in cmds-subvolume.c
The patch also fixes some coding styles problems.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-10-16 08:20:03 -04:00
Zach Brown c17a056f38 btrfs-progs: use NULL instead of 0
These were mostly in option structs but there were a few gross string
pointer arguments given as 0.

Signed-off-by: Zach Brown <zab@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-09-03 19:41:11 +02:00
Qu Wenruo 3ca706a6ee btrfs-progs: Update the usage strings of some cmds
Update the usage strings of some cmds to keep the them consistent with
the source.

Also some minor changes are done to fit the man page syntax.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-08-09 14:32:37 +02:00
Wang Shilong c125b7cf43 Btrfs-progs: fix closing of opendir()
valgrind complains open_file_or_dir() causes a memory leak.That is because
if we open a directoy by opendir(), and then we should call closedir()
to free memory.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-08-09 14:32:36 +02:00
Wang Shilong 936d520a48 Btrfs-progs: listing subvols and getting default subvol don't need a subv path
Listing subvolumes and getting default subvol in the filesystem don't need a
subv path,Any valid path related to Btrfs filesystem is ok to finish the work.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-08-09 14:32:35 +02:00
David Sterba a8c9a2087a btrfs-progs: use reentrant localtime
localtime may return NULL (when an error is detected eg. after setting
tzname), followed by a segfault when the values is about to be used.
localtime_r works, does not set tzname and does not return NULL.

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-08-09 14:32:35 +02:00
Wang Shilong 705e76ee8d Btrfs-progs: fix possible memory leak related to subvolume/snapshot creation
The operation related qgroup inherit may fails, if it fails, we should
free memory allocated,otherwise, memory leak happens.

Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-08-09 14:32:33 +02:00
Wang Shilong 0ba706acd8 Btrfs-progs: fix compile warnings in i386 machine
See the warnings below:

   [CC]     btrfs-list.o
btrfs-list.c: In function 'filter_by_parent':
btrfs-list.c:1183:34: warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]
     [CC]     cmds-subvolume.o
cmds-subvolume.c: In function 'cmd_subvol_show':
cmds-subvolume.c:917:5: warning: cast from pointer to integer of different size
[-Wpointer-to-int-cast]
     [CC]     cmds-restore.o
cmds-restore.c: In function 'decompress_lzo':
cmds-restore.c:116:10: warning: passing argument 4 of 'lzo1x_decompress_safe'
from incompatible pointer type [enabled by default]
In file included from cmds-restore.c:31:0:
/usr/include/lzo/lzo1x.h:77:1: note: expected 'lzo_uint *' but argument is of
type 'size_t *'

Reported-by: Russell Coker <russell@coker.com.au>
Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-05-10 10:55:22 -04:00
Koen De Wit c38d9ca6f2 btrfs-progs: add quota-related info to usage messages
Extending usage messages with some info on the quota functionality:
     - The -i option of "subvol create" and "subvol snapshot" was not
documented
     - The -c option of "qgroup limit" is the default option
     - The "qouta rescan" command is not yet implemented, while it should be
       executed after enabling quota on a non-empty filesystem.

Signed-off-by: Koen De Wit <koen.de.wit@oracle.com>
2013-04-23 18:56:21 +02: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
Eric Sandeen 6ddd81d6d7 btrfs-progs: Free resources when returning error from cmd_snapshot()
cmd_snapshot() 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:00:42 +01:00
Eric Sandeen 186638ea98 btrfs-progs: tidy up cmd_snapshot() whitespace & returns
Just whitespace fixes, and magical return value removal.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-03-10 16:00:19 +01:00
Eric Sandeen 0b9e200099 btrfs-progs: close fd on cmd_subvol_list return
stops an fd leak that Coverity found.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-03-10 15:48:43 +01:00
Eric Sandeen fb631862c9 btrfs-progs: fix fd leak in cmd_subvol_set_default
Rearrange cmd_subvol_set_default() slightly so we
don't have to close the fd on an error return.

While we're at it, fix whitespace & remove magic
return values.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-02-27 14:40:05 +01:00
Eric Sandeen e54ba43cde btrfs-progs: close fd on cmd_subvol_get_default return
Without this we leak the fd when we return from the
function.

Also, remove the senseless random return values.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-02-27 14:39:56 +01:00
Eric Sandeen b808cb66aa btrfs-progs: btrfs_list_get_path_rootid error handling
btrfs_list_get_path_rootid() tries to return a negative
number on error, but it's a u64 function.  Callers which test
for a return < 0 will never see an error.

Change the function to fill in the rootid via a pointer,
and then return a simple int as error.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-02-27 14:39:27 +01:00
Eric Sandeen bcb2b73358 btrfs-progs: simplify ioctl name copy and null termination
In the places where we copy a string into the name
member of btrfs_ioctl_vol_args or btrfs_ioctl_vol_args_v2,
we use strncopy (to not overflow the name array) and then
set the last position to the null character.

Howver, in both cases the arrays are defined with:

        char name[MAX+1];

hence the last array position is name[MAX].

In most cases, we now insert the null at name[MAX-1]
which deprives us of one useful character.

Even the above isn't consistent through the code, so
make some helper code to make it simple, i.e.
strncpy_null(dest, src) which automatically does the
right thing based on the size of dest.

Thanks to Zach Brown for the macro suggestion.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-02-05 16:09:41 -08:00
Eric Sandeen 7ced17b07f btrfs-progs: fix name lengths in cmd_subvol_create
cmd_subvol_create() calls either BTRFS_IOC_SUBVOL_CREATE
or BTRFS_IOC_SUBVOL_CREATE_V2 depending on whether or
not inherit is set.  However, these 2 ioctls have different
args structures with different length name[] members.

In the BTRFS_IOC_SUBVOL_CREATE case, the arg is
btrfs_ioctl_vol_args, with a BTRFS_PATH_NAME_MAX length
name, not a BTRFS_SUBVOL_NAME_MAX length name.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-02-05 16:09:41 -08:00
Zach Brown bf4196b408 btrfs-progs: don't leak inherit on errors
A few paths returned errors before freeing their inherit allocation.

Signed-off-by: Zach Brown <zab@redhat.com>
2013-02-05 16:09:40 -08:00
Zach Brown ceb538f178 btrfs-progs: close ioctl fd in find new
Signed-off-by: Zach Brown <zab@redhat.com>
2013-02-05 16:09:40 -08:00
Zach Brown 201238df26 btrfs-progs: don't close(<0) in subvol create
Don't try to close an fd immediately after discovering that opening it
failed.

Signed-off-by: Zach Brown <zab@redhat.com>
2013-02-05 16:09:39 -08:00
Anand Jain aebc64f01e Btrfs-progs: dont print uuid unless -u option is given
unless it was intentional to include uuid when -s
option is (show snapshot only) given, we would need
this break statement.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
2013-02-01 17:42:14 +01:00
David Sterba 58cc1ef8df btrfs-progs: add option c to show ogeneration
This will also pair the 'C' filter.

Signed-off-by: David Sterba <dsterba@suse.cz>
2013-02-01 17:19:49 +01:00
David Sterba f7fef0d242 btrfs-progs: add option g to show generation
Add 'g' to pair the 'G' filter.

Signed-off-by: David Sterba <dsterba@suse.cz>
2013-02-01 17:08:57 +01:00
David Sterba bd82f40c73 btrfs-progs: upcase filter options
Rename filter options in 'subvol list' subcommand, that way we can
distinguish them from the options that just show some option in the
output and can have a matching uppercase filter.

Signed-off-by: David Sterba <dsterba@suse.cz>
2013-02-01 17:02:27 +01:00
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