Commit Graph

97 Commits (466e066837898ec047165b8f1081c529092c6d0a)

Author SHA1 Message Date
Zhao Lei 2dfb710803 btrfs-progs: subvolume: use btrfs_open_dir for btrfs subvolume command
We can use btrfs_open_dir() to check whether target dir is
in btrfs's mount point before open, instead of checking it in
kernel space of ioctl, and return fuzzy error message.

Before patch:
  # (/mnt/tmp is not btrfs mountpoint)
  #
  # btrfs subvolume create /mnt/tmp/123
  Create subvolume '/mnt/tmp/123'
  ERROR: cannot create subvolume - Inappropriate ioctl for device
  #

After patch:
  # btrfs subvolume create /mnt/tmp/123
  ERROR: not btrfs filesystem: /mnt/tmp
  #

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-11-02 09:35:00 +01:00
David Sterba d3be5b65da btrfs-progs: subvol sync: fix reversed condition
In my local change to 07cc891d1d
("btrfs-progs: Simplify all-subvolumn-clean condition for
wait_for_subvolume_cleaning") that reversed the meaning of the variable
dirty -> clean, I made a mistake and broke 'subvol sync' that will not
wait as expected and ends prematurely. Zhao Lei's original patch worked.

CC: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-10-07 12:13:47 +02:00
Zhao Lei 07cc891d1d btrfs-progs: Simplify all-subvolumn-clean condition for wait_for_subvolume_cleaning
Instead of using a dirty-subvolumn-counter in old code, this patch
turn to use a simple and direct way:
  If (not dirty-subvolumn found in current loop) {
      return all_clean;
  }

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-01 14:02:49 +02:00
Zhao Lei 601c5e1b23 btrfs-progs: Simplify memory allocation for enumerate_dead_subvols
No need prepare memory for enumerate_dead_subvols() in caller, and pass
additional argument for allocated length.

Just do every thing inside enumerate_dead_subvols(), it will not
increase malloc count, but make code simple.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-01 14:02:49 +02:00
Zhao Lei 298746b958 btrfs-progs: Fix wrong return value of wait_for_subvolume_cleaning()
Reproduce:
 # btrfs subvolume sync /mnt/btrfs
 Subvolume id 323 is gone
 # echo $?
 1
 #

Reason:
 wait_for_subvolume_cleaning() return !0 in right case, because
 value of ret is set to "is subvolume clean" state before return.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-01 14:02:49 +02:00
Zhao Lei 6425752ab2 btrfs-progs: Fix infinite loop of btrfs subvolumn sync
We can trigger the bug by following operation:
  (no wait between commands 3~5)
  btrfs subvolume create /mnt/btrfs/mysubvol
  btrfs subvolume snapshot /mnt/btrfs/mysubvol /mnt/btrfs/mysubvol_snap
  btrfs subvolume delete /mnt/btrfs/mysubvol_snap
  btrfs subvolume delete /mnt/btrfs/mysubvol
  btrfs subvolume sync /mnt/btrfs
The last command will not exit.

Reason:
  List of "deleted subvolumes" are not currectly set.

  It caused by a typo of value assign, in detail:
  *ids[idx] = sh->offset;
  should be:
  (*ids)[idx] = sh->offset;
  So only first element is set to right memory address.

  If there are multiple "deleted subvolumes", program will
  keep wait.

Above typo also caused some segment fault in my test.

This patch fixed above bug.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-01 14:02:48 +02:00
Zhao Lei 64650e13bb btrfs-progs: remove code for setup mntid in cmd_subvol_show
We don't need to use value of mntid in cmd_subvol_show(), no need
to get its value.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-08-31 19:25:14 +02:00
David Sterba c6cf9778e8 btrfs-progs: unify naming of command handlers
Use cmd_ + group + command schema.

Signed-off-by: David Sterba <dsterba@suse.com>
2015-08-31 19:25:09 +02:00
David Sterba 6a039e5063 btrfs-progs: properly set up ioctl arguments
At some places we do not clear the whole ioctl structure and could
pass garbage to kernel. Zero the ioctl vol_args and use a helper for
copying the path.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-12 16:44:48 +02:00
David Sterba 76a9be2e72 btrfs-progs: add helper to wait for subvolume cleaning
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-09 19:36:30 +02:00
David Sterba c9f885ec89 btrfs-progs: subvol: let sync check only current deletions
So far the subvol sync command takes a shortcut and looks if there are
any deleted subvols at all. It does not print the deleted subvolumes as
they get cleaned. Arguably this is what the user would like to see and
has to do

 $ btrfs subvol sync /path $(btrfs subvol list -d /path | "extract the ids")

to see the progress.

Make it look for all currently deleted subvolumes automatically and
print the progress as if the ids were listed manually.

This is a slight change in the semantics of the command. Previously, any
new subvol deletion would prevent subvol sync to return. To simulate the
old behaviour, run 'subvol sync' in a loop until it returns 0.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-09 18:18:19 +02:00
David Sterba 330709ee13 btrfs-progs: add command group info strings
They're printed in the 'btrfs' command group summary.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-09 14:26:33 +02:00
David Sterba d020af5235 btrfs-progs: subvol show: tweak output
- capitalize UUID
- print otime with timezone
- rename 'Object ID' to 'Subvolume ID'
- add ID to Parent and Top level

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-03 12:52:56 +02:00
David Sterba 67db275e90 btrfs-progs: subvol show: print received uuid
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-03 12:52:52 +02:00
David Sterba 08f9acadab btrfs-progs: getopt, use symbolic name for argument requirements
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-04-08 17:39:51 +02:00
David Sterba 2b7cdab425 btrfs-progs: make getopt tables static const
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-01-19 13:44:49 +01:00
David Sterba ecbf1339a6 btrfs-progs: cleanup, move getop long options close to their use
Move long_option defintions just before getopt_long everywhere.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-01-19 13:30:06 +01:00
Gui Hecheng 3d47cc9ae1 btrfs-progs: remove uneccessary subvol name check for subvol deletion
When we want to delete a subvol, we first check to see whether it is
a subvolume or not. After the check, we are sure that it is a valid
subvol, don't have to check its name.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
[removed unused variable 'len']
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-01-14 18:34:04 +01:00
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